How to make an activity stop, rather then be destroyed, from the BACK key?

前端 未结 7 1327
心在旅途
心在旅途 2020-12-15 07:02

Right now an activity gets destroyed when the BACK key is pressed. How can I make it just stop ( i.e. keep all the variables, etc. alive ), rather then be destroyed?

7条回答
  •  佛祖请我去吃肉
    2020-12-15 07:45

    Just specify in the manifest for the activity as

     android:persistent="true"
    

    That should prevent your activity getting destroyed. To know more about this please refer to these below links which were answered by me

    How to prevent call of onDestroy() after onPause()?

    Prevent activity from being destroyed as long as possible

    In the above posts I have explained in detail with a use case

提交回复
热议问题