Go To Home Screen Instead Of Previous Activity
I know this question has been asked many times before, but any of the solution is not working and my situation is a little bit different. I've an Activity which can be called from
Solution 1:
you can override onBackPressed()
method as follows. It should work.
publicvoidonBackPressed() {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
Solution 2:
You could also simply call the finish()
method on the activity.
Solution 3:
And Adding to this question if you dont want to back your activity where you pressed back button then just a finish()
below the code.
publicvoidonBackPressed() {
Intent mainActivity = new Intent(Intent.ACTION_MAIN);
mainActivity.addCategory(Intent.CATEGORY_HOME);
mainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mainActivity);
finish();
}
Solution 4:
Simply if you go to back Home activity than add this code
@Override
publicvoidonBackPressed()
{
Intent intent=new Intent(currentactivity.this,Mainactivity.class);
startActivity(intent);
finish();
}// on back Pressed first add activity where you stand and add activity where you go
Solution 5:
Just send an Intent directly home. This can be done through setting the action and category of that intent.
Check the documentation on Intent for details.
Post a Comment for "Go To Home Screen Instead Of Previous Activity"