variables retaining values after app close

前端 未结 6 640
情歌与酒
情歌与酒 2021-01-28 11:23

My app is retaining all of the variable values when it closes and this is effecting how it runs when reopened. Is there any way to reset them all upon app close? or is there a w

6条回答
  •  礼貌的吻别
    2021-01-28 11:46

    You need to familiarize yourself with the Activity Lifecycle.

    You could leverage onResume() to reset your variables; also note onDestory() and onPause().

    UPDATE:

    Killing the application in its entirety each time the app moves to the background is an anti-pattern. You should really look at your application and follow the aforementioned activity lifecycle pattern and take the needed steps to insure your variables exist as you desire based on state.

提交回复
热议问题