Background
I am using AccountManager
with a custom account type. In the beginning the App starts the user LogInActivity and a token recieved by the server is stored within the account. The tokens are used by some Worker
organized by WorkManager
to sync data in the background. Each worker is requesting the token with AccountManager#getAuthTokenByFeatures()
. When the user is changing the password on the website connected with the server, the token is expired and the AccountManager
is starting (due to password change) the related LogInActivtiy.
Issue If during the user input of the new login data other (parallel running) Worker
are requesting an AuthToken, the LogInActivity is started multiple times.
Solution Approach
Setting
android:launchmode="singleInstance"
of LogInActivity -> only one Activity is started, but second, third, ... callingWorker
results in deadlock due to no return ofAccountManagerFuture<Bundle>
.Creating Workaround:
AccountAthenticator
checks if an Instance ofLogInActivity
is allready running in Foreground and starts all further Activities invisible in the background. If LogIn was successfull all in the background running LogInActivities recieving necessary Information viaLocalBroadcastManager
->LocalBroadcastManager
is deprecated, power consuming and unnecessary overhead
Is the use of AccountManager
in combination with WorkManager
correct in this case?
Might there any configuration issue with AccountManager
causing this behavior?
Any other solution approaches?
Help is really appreciated. Thank you!