Libathos
Libathos

Reputation: 3362

An Android scenario that puzzles me

This is how I have organized my data:

Now the scenario that puzzles me: In a certain Activity If a button is pressed

  1. I check if there is an internet connection
  2. If there isn't one I start an Intent to open Settings for the user to enable mobile networks or WiFi

when It returns though it seem that the application is destroyed because onCreate is called again but at that time the arrayList in my Application class is this time null. So my questions are

this Is how I've declared the ArrayList of objects in my Application class

        private static ArrayList<PointOfInterest> pois;

EDIT: I put a Log.i() on onDestroy() of the Activity and it was never printed. But on When I returned from the Settings, onCreate() was called (without onDestroy having been called), how is that possible?

Upvotes: 0

Views: 157

Answers (1)

Jfreu
Jfreu

Reputation: 589

Static fields can be nullified by the os when the application is in background. So they should always be restored.

see this post

Upvotes: 1

Related Questions