Reputation: 15039
In my android app, I have two activities
mainactivity and erroractivity
main activity starts (on resume) it checks wifi-not connected it opens the error activity, which simply tells user wifi is off start it and then open the app
User now starts wifi - reopens my app, the last activity which was error activity now shows up again. So in the onResume of error activity I check wifi state if connected I open the main activity using startActivity .
User is now on mainactivity but here comes the bug,
User now can no-longer press back button to end the main activity, because when he presses back, it seems to go to erroractivity which again opens the mainactivity,
Any ideas how to sort it out ?
Thanks,
Upvotes: 0
Views: 143
Reputation: 7266
On the onResume()
of erroactivity, instead of launching mainactivity with startActivity()
use finish()
, to finish the erroractivity and go back to the the previous one on the stack (i.e. mainactivity).
Upvotes: 1
Reputation: 7435
Since you are not finishing the MainActivity you just need to call finish()
in the error activity onResume()
method if the wifi is connected...
Upvotes: 1
Reputation: 86948
which simply tells user wifi is off start it and then open the app
I assume that you send the user to the WiFi settings with an Intent and startActivity()
. Try calling finish()
after startActivity()
.
Upvotes: 1