Using AuthenticatorActivity as application signin
-
01-07-2021 - |
Domanda
My app requires a sync adapter and therefore requires some authentication to take place before an account can be added to the Accounts & Sync
.
I have followed the sample sync adapter app and have my app setup. I can for instance now verify a user on my server and have an account added to the Accounts & Sync
section.
The thing is I would prefer this precedure of adding an account via the AuthenticatorActivity
to take place inside my app for a better user experience.
So far I have added the AuthenticatorActivity
when my app launches. As soon as authentication is successful it launches the Accounts & Sync
settings section which completely ruins the applications signin/signup experience.
How can I stop this behaviour (launch of the Accounts & Sync
setting on success) and allow my app to move to my next chosen step?
Soluzione
It is relatively simple procedure:
Make sure instead of using startActivity
you use startActivityForResult
.
Intent intent = new Intent(this, ClassYouAreLaunching.class);
startActivityForResult(intent, 0); // 0 reflects the requestCode seen in onActivityResult
Then you make sure you can capture the intent once it is sent back to you from the origin intent.
onActivityResult(int requestCode, int resultCode, Intent intent) {
if( resultCode == Activity.RESULT_CANCELED ) {
finish();
} else {
// MAYBE
switch( requestCode ) {
...
}
}
}