Reputation: 177
For my case, I am developing an app that can call system application such as internal SMS application and others. What I want to do is I would like to go back to home screen instead of my app or previous system application that I called before when back button is pressed after SMS application is launched, which means that I want to close all previous activity or any intent activity before I call next system application.
Thank you in advance.
Upvotes: 0
Views: 5444
Reputation: 2581
I think you cannot override back button behavior of any other application like a system application.
And to show the home screen,
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Good Luck :)
Upvotes: 3
Reputation: 2824
You can call finish() and set flag as clear top before going to other Activity.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share Text To..."));
finish();
Upvotes: 2