Skip to content Skip to sidebar Skip to footer

Why Is My Accountauthenticatoractivity Not Launching When Triggered By Another App?

I have a suite of apps and my AccountManager files live in one central app. I can use AccountManager.AddAccount() in that central app, but when I try to use that method from the ot

Solution 1:

So I could not figure out why AddAccount() would not launch the activity itself, but I was able to find a workaround. I was able to just handle the intent myself.

This is my code snippet where I begin adding a new account (from any app):

var adapter = newAccountPickerArrayAdapter(this, accounts);
            var builder = newAlertDialog.Builder(newContextThemeWrapper(this, Resource.Style.AppTheme));
            builder.SetTitle(Resource.String.choose_account);
            builder.SetAdapter(adapter,
                (s, a) =>
                {
                    var dialog = (AlertDialog)s;
                    dialog.Dismiss();
                    GetExistingAuthToken(accounts[a.Which]);
                    FinishLogin(accounts[a.Which]);
                });
            builder.SetNeutralButton(Resource.String.add_new_account,
                (s, e) =>
                {
                    var dialog = (AlertDialog)s;
                    dialog.Dismiss();
                    var thread = newThread(AddNewAccount);
                    thread.Start();
                    CheckIfFirstRun();
                    Finish();
                });
            builder.Create().Show();
        }

        voidAddNewAccount()
        {
            var future = _accountManager.AddAccount(AccountKeys.ACCOUNT_TYPE, AccountKeys.AUTH_TYPE, null, null, null, null, null);
            var bundle = future.ResultasBundle;
            if (bundle != null)
            {
                var intent = bundle.GetParcelable(AccountManager.KeyIntent) asIntent;
                StartActivity(intent);
            }
        }

By sending nullas the Activityin AddAccount(), the desired intent is returned in a bundle. I can then just launch that intent directly.

I also needed to add (Exported = true) to the manifest entry for my AccountAuthenticatorActivity. This lets other apps launch that activity.

Post a Comment for "Why Is My Accountauthenticatoractivity Not Launching When Triggered By Another App?"