title: Instance variable getting set to null if activity is recreated by OS
body: <p>I have been struggling with this problem for quite some time now. </p>
  
  <p>Instance variables of my main activity are getting set to null if I start app after a day. So, for my users every other day app crashes once and then restarts just fine. I am assuming that the activity gets killed and recreated and when they start app the next day.</p>
  
  <p>Basically, what may be happening is due to "onsavedinstance" the views are getting recreated, but the data that those views need is not yet available as I do not store the data in the bundle.</p>
  
  <p>How can I prevent it? I am not inclined towards storing each and every variable in bundle as it's a bad design. What's the best way to do it?</p>
  
  <p>Here is my code:</p>
  
  <p>Basically i am trying to populate my bootstrap data (dataWrapper) from server on "onCreate". I use this data object in subsequent code. All works fine on first app launch. But when user opens app after a day or 7-8 hours, the object "dataWrapper" turns out to be null.</p>
  
  <pre><code>    protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          //other initialization code
          getData();
          //remaining code
      }
  
      protected DataWrapper dataWrapper;
  
      private void getData(){
      try {
          //url for fetching data 
          String url = "http://....."
          new FetchAndPopulateMarketDataAsyncTask(this){
              @Override public void onPostExecute(DataWrapper result)
              {
                  if(result==null){
                      //server or no internet error 
                  }
                  else{
                      dataWrapper = (DataWrapper)result;
                  }
              }
          }.execute(new URL(url));
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Thanks,
  Rony</p>