App crashes when restoring from background after a long time

前端 未结 5 1573
执笔经年
执笔经年 2020-12-05 10:57

My application crashes after idling for a long time in the background. I debugged and found the reason that it is crashing is due to a NullPointerException. Exc

5条回答
  •  没有蜡笔的小新
    2020-12-05 11:29

    If you can, store it in other methods. If its complex data structures, you may have to restart the app. For example, I have a User singleton in my app that holds login info for my server. I couldn't save those if I tried- a lot of the data is hidden in AWS variables. What I had to do was detect when we were being relaunched from the home page after being cleaned up (as opposed to just being restarted) and launched my starting activity, then finished the current activity. And I had to add that to every activity in my app.

提交回复
热议问题