Reputation: 2630
I need to show a EULA like dialog when a user starts up my app, but my app also has a splash screen of sorts that needs to be displayed before the dialog. I coded this up like so:
Activity A.onCreate(...) {
...
1. startActivity(Activity B) [this activity calls .finish() after x seconds]
2. dialog.show()
...
}
Logically, it seems like this should work. However, after I return to activity A from activity B, the entire screen is dimmed as if the dialog is showing, but without the dialog window.
I was able to work around this by reversing the calls as such and the dialog shows after activity B is done and no weird issues occur:
Activity A.onCreate(...) {
...
1. dialog.show()
2. startActivity(Activity B) [this activity calls .finish() after x seconds]
...
}
Anyone know why the order of calls is so important? To me they should work the same.
Upvotes: 2
Views: 1326
Reputation: 46844
Both of those functions are asynchronous functions. This means that the code execution does not pause on them, but continues on to call the next lines.
Instead of calling them one right after the other, you need to wait for the one to return before calling the next. If you want to show the Dialog first, add an onDismissListener to listen for when the dialog is closed. Within that listener you can start the next activity.
Upvotes: 3