Public static variables and Android activity life cycle management

后端 未结 3 1387
無奈伤痛
無奈伤痛 2020-12-03 02:48

According to the documentation the Android OS can kill the activity at the rear of the backstack.

So, say for example I have an app and open the Main Activity (let\

3条回答
  •  悲哀的现实
    2020-12-03 03:18

    The answer is (3). If you need to keep values, persist them in shared preferences when each activity pauses and restore them when it resumes. Alternatively, you can also maintain an "initialized" static flag and re-initialize the static variables from any activity's onCreate() method if it is false.

提交回复
热议问题