Go to home screen instead of previous Activity

2020-02-25 08:11发布

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 many different Activities. But I want when the user presses back button, instead of previous activity, app should go to Home screen.

One way to use StartActivityFromResult() but then I'll have to use it in every calling Activity.

7条回答
放我归山
2楼-- · 2020-02-25 09:00

Simply if you go to back Home activity than add this code

@Override
public void onBackPressed()
{

    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
查看更多
登录 后发表回答