问题
I have an activity which, when started, needs to check if the user is authenticated. If not, I need to display an interface to authenticate. I do this with another activity, which has a dialog theme, and I start it in onResume() with flags NO_HISTORY and EXCLUDE_FROM_RECENTS.
Everything works fine when starting the application for the first time. But I have a feature that resets login after some time, if the user is not in an activity. When I test this, I start the applicatio, enter the password, then move back to home. Then when I enter the application again, the background darkens as if the dialog would show, but it doesn't.
At this point, if I press the back button, the darkening from the background activity disappears for a second, then the dialog finally appears.
I used logcat to investigate the case, and the activity lifecycle functions get called properly:
//For the first start:
onCreate background activity
onStart background activity
onResume background activity
onPause background activity
onCreate dialog
onStart dialog
onResume dialog
//Enter password
onPause dialog
onResume background activity
onStop dialog
onDestroy dialog
//navigating to homescreen
onPause background activity
onStop background activity
//starting again
onRestart background activity
onStart background activity
onResume background activity
onPause background activity
onCreate dialog
onStart dialog
onResume dialog
//no dialog shown, only darkened background activity recieving no input
//pressing back button
onPause dialog
onResume background activity
onPause background activity
onCreate NEW dialog
onStart NEW dialog
onResume NEW dialog
onStop OLD dialog
onDestroy OLD dialog
//now the dialog is properly shown
//entering password
onPause NEW dialog
onResume background activity
onStop NEW dialog
onDestroy NEW dialog
Using the SINGLE_TOP flag makes no change. However, if I remove the dialog theme from the dialog activity, it IS shown after the restart.
So far I didn't want to use a Dialog instead of an Activity, because I consider them problematic sometimes and less encapsulated and this part has to be quite secure. You may be able to convince me though..
Thank you in advance!
来源:https://stackoverflow.com/questions/9963976/android-dialog-themed-activity-not-visible