title: Android switching from activities
body: <p>I am making an Android app that has the <code>MainActivity</code> in it's <strong>onCreate</strong> check if it has to download a file. The check happens in a <strong>AsynchTask</strong> class. 
  I have a second activity <code>PrefsActivity</code> that launches a <code>Prefsfragment</code> for preferences.</p>
  
  <p>Now when I come back from the <code>PrefsActivity</code>,  <strong>onCreate</strong> is issued again.
  But the whole check doesn't have to happen again. </p>
  
  <p><strong>Code leading to preferences</strong></p>
  
  <pre><code>public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.preferences:
              Intent intent = new Intent(this, PrefsActivity.class);
              startActivityForResult(intent, 1);
              return true;
          default:
              return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p><strong>Code for preferences</strong></p>
  
  <pre><code>public class PrefsActivity extends Activity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment()).commit();
  
      ActionBar actionBar = getActionBar();
      actionBar.setDisplayHomeAsUpEnabled(true);
  }
  }
  </code></pre>
  
  <p>Code for starting Asynchtask in MainActivity</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      PropertiesManager.getUniqueInstance().loadProperties(PropertiesManager.PROPERTIES_FILE, this);
  
      SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
      boolean auto_update = sharedPreferences.getBoolean("pref_autoUpdate", true);
      File downloadFile = getExternalFilesDir("media/" + Downloader.DOWNLOAD_FILE_NAME);
  
      if (auto_update || !downloadFile.exists()) {
          try {
              if (new Downloader(this).execute().get()) {
                  receiveBroadcast(this);
              } else {
                  schedule = Parser.getUniqueInstance().parse(this);
                  ScheduleBuilder.getUniqueInstance().build(this, (DayBean) schedule.get(9));
              }
          } catch (InterruptedException ex) {
              Log.e(TAG, ex.getMessage());
          } catch (ExecutionException ex) {
              Log.e(TAG, ex.getMessage());
          }
      } else {
          schedule = Parser.getUniqueInstance().parse(this);
          ScheduleBuilder.getUniqueInstance().build(this, (DayBean) schedule.get(9));
      }
  }
  </code></pre>