Reputation: 1562
if a user tapped the home button and open the app after that, how to not allow back? eg don't allow users to go back to screens that they seen before tapping the home button. It should be treated as a new session
Upvotes: 1
Views: 951
Reputation: 83301
This sounds like a bad idea, as it blatantly goes against the Android task/navigation guidelines.
The user expects to be able to back out to the previous screen after resuming a task... and preventing it will potentially piss off a lot of users.
Please, please, please read these documents before you risk destroying the user experience.
Upvotes: 2
Reputation: 73996
The home button cannot be overridden nore should it, if you dont want the user to go back to the activity they left when the home button was clicked then on the on pause of the activity just pop the backstack to where you want to be.
Upvotes: 1
Reputation: 38866
If you want to end your Activity once it is no longer visible then finish your activity in your Activities call to onStop().
@Override
protected void onStop() {
super.onStop();
this.finish();
}
This will finish your Activity with no chance of onRestart() being called. Be careful with this method because users expect to resume the app instead of having to start over, but there are cases where this would be the accepted protocol. See more on Navigation and the Activity LifeCycle.
Edit: Also see the question Android-Quittings an application - is that frowned upon? specifically this answer.
Upvotes: 0