I have an Activity which keeps beeping till the time the user clicks a button. On clicking the button, it displays a message. After displaying the message, instead of the user pressing on the back button to exit, I want my activity to exit to the home screen on its own.
Does the finish()
method do this? If yes, how and where should I implement it?
Any kind of help will be appreciated. Thanks
Intent i= new Intent("package.homescreenactivity");//homescreen of your app.
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
finish();
Go back to home screen by clearing activity stack.
To understand the whole concept i suggest you take a look at this site. http://developer.android.com/guide/components/tasks-and-back-stack.html. The site talks about how activity back stack works.
Update: (August 15th 2014)
Clearing Backstack may not be a good idea. Please have a look at Effective Navigation design guidelines.
Back button is supposed to take you back to the previous activity.
Check
http://developer.android.com/design/patterns/navigation.html