Calling finishAffinity() does not destroy android app or activity. Activity's data still persists even when app is restarted

后端 未结 2 1596
粉色の甜心
粉色の甜心 2021-01-02 01:26

This is a huge Android Programming issue/bug.

Calling finishAffinity() does not shut down my application.
This is evidenced from the fact that:

2条回答
  •  独厮守ぢ
    2021-01-02 01:44

    Android has no concept of "shut down my application". There is only the Android Activity life cycle. There is not a connection between the VM's object life cycle on the activity life cycle; Android is free to re-use your Activity object instance across on create / destroy boundaries. In short, you can't assume Android will ever construct a new Activity object to handle a life cycle event.

    You'll need to manage your own state. For example, maybe you want to clear them in onCreate() so whenever you activity is re-created they are reset. Note that I don't presume to know what logic you want to apply to the problem, I'm just giving an example.

提交回复
热议问题