What are the chances that the singleton "instance" variable becomes null in an Android application when switching between actions?

I have a singleton, typical design with a static "mInstance" for storing global state. I notice that sometimes when switching between actions, the mInstance variable becomes empty and requires re-instantiation, as a result of which all data remains empty.

Is this expected, or am I doing something wrong? Is it likely that static singleton variables will be nullified in such a scenario? I seriously doubt it and would like to hear some opinions.

Code inserted:

public class RuleManager extends ArrayAdapter<Rule>
{
  private static RuleManager mInstance;
  private final Context context;
  public RuleManager(Context context, List<Rule> r)
  {
    super(context,R.layout.main_menu_options_list_item);
    if(r==null)r=new ArrayList<Rule>();
    this.context=context;
  }

  public static RuleManager getInstance(Context context,List<Rule> r) 
  {
      if (mInstance == null)
          mInstance = new RuleManager(context, r);
      return mInstance;
  }   
}

, , , , , .

0
2

. , . getInstance.

+1

, Singleton, LifeCycle. .

0

All Articles