0

We build an Android Launcher and have some strange behaviour with onDestroy() and finish(). According to the docs and this post, isFinishing() should only be true if finish() is called on the Activity. However, while finish() is never called on the MainActivity, isFinishing() is true in the MainActivity's onDestroy() method.

The first time after creating the MainActivity, when a user installs or uninstalls an app through the Play Store, the onDestroy() of the MainActivity is called after exiting the Play Store. This only happens the first time, after that the onResume() method is called as expected, without recreating the MainActivity.

I'm checking whether isFinished() is called like this:

@Override
public void finish() {
    // (Never called)
    super.finish();
    Log.i(TAG, "Finish called. " + isFinishing()); 
}

@Override
public void onStop() {
    super.onStop();
    // When opening the Play Store app, isFinishing is false here
    Log.i(TAG, "onStop called. Finishing: " + isFinishing()); 
}

@Override
public void onDestroy() {
    super.onDestroy();
    // When exiting the Play Store app (opening our Launcher), isFinishing is true the first time,
    // after that onDestroy isn't called anymore.
    Log.i(TAG, "onDestroy called. Finishing: " + isFinishing()); 
}

Does anyone know why onDestroy is called the first time after installing / uninstalling an app? Thanks!

Jorn Rigter
  • 745
  • 1
  • 6
  • 25
  • 1
    The docs clearly state: _Check to see whether this activity is in the process of finishing, either because you called finish() on it or someone else has requested that it finished._ – ashu May 10 '21 at 10:39
  • Indeed, I read the docs as well. But wouldn't finish() be called on the MainActivity in that case? Since it's never called. And what other process could call finish for my activity? Could it be the Play Store app? – Jorn Rigter May 10 '21 at 10:41
  • 1
    The framework could destroy activities as it deems necessary. It doesn't need to call finish(). The language in the docs is ambiguous; it doesn't state explicitly that _someone_ has to call finish(). AFAIK, _someone_ is the framework, and _"requested that it finished"_ doesn't necessary mean that it has to call finish() on the activity. – ashu May 10 '21 at 10:46
  • on second thought, someone could be any application that can request the framework to kill other processes. – ashu May 10 '21 at 10:47
  • Thanks, that's helpful. I checked [this SO post about determining if your app process is killed by the system](https://stackoverflow.com/questions/21040339/how-to-know-when-my-app-has-been-killed) and it seems like that is happening. Not sure why though, but I'll look into that. – Jorn Rigter May 10 '21 at 10:58
  • I suppose that _force close_ is the keyword there. We aren't talking about force close here. – ashu May 10 '21 at 11:06

0 Answers0