Skip to content Skip to sidebar Skip to footer

Global Variable Becomes Null Sometimes

I have a variable declared in my base base that extends Application. The variable is static and i am able to set it and access it just fine. However on some devices it is null som

Solution 1:

Where in your app do you initialize nextPage?

I would recommend adding nextPage = new ArrayList<String>(); in onCreate of Application, or simply directly in the field variable.

If you initialize nextPage in an activity, then a possible scenario of null could be:

  • App starts
  • Activity starts - nextPage is set and valid
  • User leaves the App
  • Android destroys App (possibly after some time)
  • A broadcast is sent (if you have defined broadcast listening in manifest)
  • App is started (but not Activity)
  • The nextPage list is null

Not knowing how your app is working, this is a thought example but could be an indication of your problem.

Post a Comment for "Global Variable Becomes Null Sometimes"