简体   繁体   中英

Why my android application's all static variables are destroyed when the app is in background for a long period of time?

If I leave my the application in background for about 12 hours, all the static variables are erased and the application goes nuts.

Why does this happen ?

What is the correct way to keep application level (scope) variables that are never destroyed until the application terminates ?

Thanks in advance, Afzal

您的应用程序可能被系统破坏了,您应该使用onSaveInstanceState onRestoreInstanceState机制保持应用程序的状态。

Your application obviously gets destroyed. You should consider the situation as relaunched.

I think 12 hours is too big a time for Android to keep your app in memory. In this time, probably your app, looks like is destroyed by Android.

So, best bet is to try to save your state / data to database onDestroy() of the activity. Look at Android's Component Cycle .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM