title: Android - restoring state when process has been killed
body: <p>I have an activity with fragments in Android, and if I minimize the app and after a while the system kills the process, later when I run the app it crashes, because it tries to resume from the second activity (the one with fragments), even though the process has been killed and it is NOT a launcher activity.
  The reason it crashes is because in the fragments some view use variables from a Singleton class, and when the process is killed all those variables become null.
  So I tried with a check in the parent activity that hosts the fragments like this </p>
  
  <pre><code>public class SecondActivity extends FragmentActivity {
  
      FragmentTabsAdapter tabsAdapter;
      ViewPager mViewPager;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Log.e("Crash", "Second Activity");
          if (Commons.INST.someVariableFromTheSingleton == null) {
              Intent i = new Intent(this, SplashScreen.class);
                          // Splash screen is the launcher activity
              startActivity(i);
          } else {
              setContentView(R.layout.activity_second);
              tabsAdapter = new FragmentTabsAdapter(getSupportFragmentManager());
              mViewPager = (ViewPager) findViewById(R.id.pager);
              mViewPager.setAdapter(tabsAdapter);
          }
      }
  
  }
  </code></pre>
  
  <p>The problem is that when it tries to restore the activity even though I explicitly stated to start the launcher activity, it still proceeds with this second activity lifecycle methods.... How do I stop it once it starts the intent?</p>