Reputation: 13164
I want to implement a Home button in my Android App which will terminate the all the Activities but the first one. Instead of user pressing the Back button again and again, I want to give user a single button which will take him/her on the first (Home) Activity. Please help how to implement it.
Upvotes: 0
Views: 2928
Reputation: 18348
I dont have the SDK on this laptop to be sure about the syntax, but i think this is it.
Set up a listener for the "home" button, in the onClick() method:
Intent i = new Intent(ActivityYouAreOnNow.this,firstActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Upvotes: 2