Afzal
Afzal

Reputation: 367

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

Upvotes: 1

Views: 717

Answers (3)

Nikolay Ivanov
Nikolay Ivanov

Reputation: 8935

You application probably get destroyed by the system you should keep state of your application using onSaveInstanceState onRestoreInstanceState mechanism.

Upvotes: 2

Prashanth Babu
Prashanth Babu

Reputation: 208

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.

Upvotes: 0

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43098

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

Upvotes: 1

Related Questions