Skip to content

Commit 6a4c76a

Browse files
committed
fix(android): use startActivity if used really early
1 parent 4528678 commit 6a4c76a

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/dialogs/dialogs.android.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function isString(value): value is string {
4040
}
4141

4242
function createAlertDialog(options?: DialogOptions & MDCAlertControlerOptions): androidx.appcompat.app.AlertDialog.Builder {
43-
const activity = androidApp.foregroundActivity as globalAndroid.app.Activity;
43+
const activity = androidApp.foregroundActivity || androidApp.startActivity as globalAndroid.app.Activity;
4444
const alert = new androidx.appcompat.app.AlertDialog.Builder(activity);
4545
alert.setTitle(options && isString(options.title) ? options.title : null);
4646
alert.setMessage(options && isString(options.message) ? options.message : null);
@@ -83,7 +83,7 @@ function createAlertDialog(options?: DialogOptions & MDCAlertControlerOptions):
8383

8484
function showDialog(builder: androidx.appcompat.app.AlertDialog.Builder, options: DialogOptions & MDCAlertControlerOptions, resolve?: Function) {
8585
const dlg = builder.show();
86-
const activity = androidApp.foregroundActivity as globalAndroid.app.Activity;
86+
const activity = androidApp.foregroundActivity || androidApp.startActivity as globalAndroid.app.Activity;
8787
if ((activity as any)._currentModalCustomView) {
8888
const view = (activity as any)._currentModalCustomView as View;
8989
const context = options.context || {};
@@ -220,7 +220,7 @@ function addButtonsToAlertDialog(alert: androidx.appcompat.app.AlertDialog.Build
220220
})
221221
);
222222
}
223-
const activity = androidApp.foregroundActivity as globalAndroid.app.Activity;
223+
const activity = androidApp.foregroundActivity || androidApp.startActivity as globalAndroid.app.Activity;
224224
alert.setOnDismissListener(
225225
new android.content.DialogInterface.OnDismissListener({
226226
onDismiss: function() {
@@ -265,7 +265,7 @@ export class AlertDialog {
265265
if (!this.dialog) {
266266
const alert = createAlertDialog(this.options);
267267

268-
const activity = androidApp.foregroundActivity as globalAndroid.app.Activity;
268+
const activity = androidApp.foregroundActivity || androidApp.startActivity as globalAndroid.app.Activity;
269269
alert.setOnDismissListener(
270270
new android.content.DialogInterface.OnDismissListener({
271271
onDismiss: function() {
@@ -438,7 +438,6 @@ export function login(arg: any): Promise<LoginResult> {
438438

439439
return new Promise<LoginResult>((resolve, reject) => {
440440
try {
441-
const context = androidApp.foregroundActivity;
442441
const stackLayout = new StackLayout();
443442
stackLayout.padding = 4;
444443
const userNameTextField = new TextField();
@@ -513,7 +512,7 @@ export function action(arg: any): Promise<string> {
513512

514513
return new Promise<string>((resolve, reject) => {
515514
try {
516-
const activity = androidApp.foregroundActivity || androidApp.startActivity;
515+
const activity = androidApp.foregroundActivity || androidApp.startActivity as globalAndroid.app.Activity;
517516
const alert = new androidx.appcompat.app.AlertDialog.Builder(activity);
518517
const message = options && isString(options.message) ? options.message : '';
519518
const title = options && isString(options.title) ? options.title : '';

src/snackbar/snackbar.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class SnackBar extends SnackBarBase {
5151
// options.actionText = options.actionText ? options.actionText : 'Close';
5252
options.hideDelay = options.hideDelay ? options.hideDelay : 3000;
5353

54-
const activity = androidApp.foregroundActivity as globalAndroid.app.Activity;
54+
const activity = androidApp.foregroundActivity || androidApp.startActivity as globalAndroid.app.Activity;
5555
let attachView = options.view || Frame.topmost().currentPage;
5656
while (attachView['_modal']) {
5757
attachView = attachView['_modal']

0 commit comments

Comments
 (0)