title: Store Objects in ApplicationContext
body: <p>When my application goes to background , my (static and singleton) objects are cleared.
  So I tried to store these objects in <strong>Applicaton Context</strong> . I am using the following code.</p>
  
  <p>Accounts.create(getApplicationContext()) will be called once to store the accounts instance.</p>
  
  <p>Is that possible(reliable) to store objects in Application Context ? I am not sure the following way is correct or not . please guide ..</p>
  
  <pre><code>   public class Init extends Application {
      private Hashtable&lt;Object, Object&gt; globalStore = new Hashtable&lt;Object, Object&gt;();
  
      public void putToGlobalStore(Object key, Object value) {
          globalStore.put(key, value);
      }
  
      public Object takeFromGlobalStore(Object key) {
          return this.globalStore.get(key);
      }
  
      public void removeFromGlobalStore(Object key) {
          this.globalStore.remove(key);
      }
  
      public boolean containsInGlobalStore(Object key) {
          return this.globalStore.containsKey(key);
      }
  }
  
  public class Accounts {
  
          protected Accounts(String name, Context context) {
              Init init = (Init) applicationContext;
                  init.putToGlobalStore(name, this);
          }
  
          private static Init applicationContext;
  
          public static void create(Context context) {
  
              if (context instanceof Application)
                  applicationContext = (Init) context;
              else
                  applicationContext = (Init) context.getApplicationContext();
  
              if (applicationContext.containsInGlobalStore(GLOBAL_NAME))
                  Logger.log("Warning " + GLOBAL_NAME
                          + " is already created. This will remove all old datas");
  
              new Accounts(GLOBAL_NAME, applicationContext);
  
  
          }
  
          private static final String GLOBAL_NAME = "accounts";
  
          public static Accounts getInstance() {
  
              try {
                  return (Accounts) applicationContext
                          .takeFromGlobalStore(GLOBAL_NAME);
              } catch (Exception e) {
                  Logger.log("GLOBAL_NAME Lost");
                  return null;
              }
  
          }
  </code></pre>
  
  <p>Please help.</p>