title: Fragment Activity - app died, no saved state
body: <p>I'm facing a very confusing issue for a very small number of my users. The error occurs when a button is pressed inside a Fragment, that starts another Fragment Activity. Here is the stack trace:</p>
  
  <pre><code>I/20:22:23.901 ActivityManager( 1668)
  Start proc com.brandall.nutter for activity com.brandall.nutter/.ActivityHomeFragment: pid=8956 uid=10125 gids={50125, 3003, 3001, 3002, 1015, 1023, 1006, 1028}
  I/20:22:23.881 WindowState( 1668)
  WIN DEATH: Window{41ed1948 u0 com.brandall.nutter/com.brandall.nutter.ActivityLinkAppsFragment}
  W/20:22:23.881 ActivityManager( 1668)
  Force removing ActivityRecord{411c4188 u0 com.brandall.nutter/.ActivityLinkAppsFragment}: app died, no saved state
  I/20:22:23.881 WindowState( 1668)
  WIN DEATH: Window{41b6a178 u0 Toast EXITING}
  W/20:22:23.881 InputDispatcher( 1668)
  Attempted to unregister already unregistered input channel '41ed1948 com.brandall.nutter/com.brandall.nutter.ActivityLinkAppsFragment (server)'
  W/20:22:23.871 ActivityManager( 1668)
  Scheduling restart of crashed service com.brandall.nutter/.TTSS in 80000ms
  I/20:22:23.871 ActivityManager( 1668)
  Process com.brandall.nutter (pid 8907) has died.
  I/20:22:23.871 WindowState( 1668)
  WIN DEATH: Window{411d4ff0 u0 com.brandall.nutter/com.brandall.nutter.ActivityHomeFragment}
  E/20:22:23.871 InputDispatcher( 1668)
  channel '41ed1948 com.brandall.nutter/com.brandall.nutter.ActivityLinkAppsFragment (server)' ~ Channel is unrecoverably broken and will be disposed!
  W/20:22:23.871 InputDispatcher( 1668)
  channel '41ed1948 com.brandall.nutter/com.brandall.nutter.ActivityLinkAppsFragment (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
  </code></pre>
  
  <p>Due to this line of the error:</p>
  
  <pre><code>com.brandall.nutter/.ActivityLinkAppsFragment}: app died, no saved state
  </code></pre>
  
  <p>I've been reading many posts about Fragment saved states, but none seem to apply in my circumstances, rather to the Fragments themselves, which aren't mentioned in the stack trace. The other posts suggest adding to each Fragment:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setRetainInstance(true);
  }
  </code></pre>
  
  <p>I currently don't override the onCreate method in any of my Fragments.</p>
  
  <p>I've also seen suggested adding this to each Fragment:</p>
  
  <pre><code>@Override
  public void onSaveInstanceState(Bundle outState) {
      super.onSaveInstanceState(outState);
      setUserVisibleHint(true);
  }
  </code></pre>
  
  <p>Apart from the fact that it's only happening to a very small number of users, the most baffling issue is with the Context used:</p>
  
  <pre><code>final Intent sa = new Intent(getActivity(), ActivityLinkAppsFragment.class);
  getActivity().startActivity(sa);
  </code></pre>
  
  <p>My application has a foreground Service and if I instead use the static Context of that (through a static getServiceContext() method) in the Intent above, the problem no longer occurs for the users and the Fragment Activity opens correctly.</p>
  
  <p><strong>I don't understand why the use of another Context should prevent the issue from happening</strong>, but I hope with the information I've supplied, it will make sense to someone!</p>
  
  <p>I can supply the FragmentPagerAdapter code I'm using if it proves to be relevant, but it's pretty standard.</p>
  
  <p>I thank you in advance </p>
  
  <p><strong>EDIT</strong> - Something very important I forgot to add. <strong>This does not cause the app to crash</strong>. Instead the Activity from which the Fragment is in, gets restarted immediately.</p>
  
  <p><strong>ANSWER</strong> - This was caused due to me calling <code>System.exit(0)</code> under circumstances I thought only possible when the user wanted to 'flush' the memory usage of the app. I was wrong and it could also be called when the user's device was handling low memory conditions. @beworker's answer below is marked as correct, as he noted <code>ActivityManagerService.handleAppDiedLocked()</code> which was a result of this.</p>