How to close activity and go back to previous activity in android

后端 未结 18 1855
孤独总比滥情好
孤独总比滥情好 2020-12-07 08:19

I have a main activity, that when I click on a button, starts a new activity, i used the following code to do so:

Intent intent = new Intent(this, SettingsAc         


        
18条回答
  •  无人及你
    2020-12-07 08:46

    I think you are calling finish() method in MainActivity before starting SettingsActivity.

    The scenario which you have described will occur in following two ways:

    EITHER

    You have set android:noHistory = "true" for MainActivity inside AndroidManifest.xml which causes MainActivity to finish automatically on pressing the back key.

    OR

    Before switching to your 'SettingsActivity', you have called finish() in your MainActivity, which kills it. When you press back button,since no other activity is preset in stack to pop, it goes back to main screen.

提交回复
热议问题