ProcessPhoenix icon indicating copy to clipboard operation
ProcessPhoenix copied to clipboard

Killed app relaunches same Activity instead of default Activity

Open edenman opened this issue 6 years ago • 6 comments

Scenario: Activity A has the LAUNCHER/DEFAULT stuff Activity B also exists

  • Launch app, A is shown
  • Click on a button that causes B to show
  • Click on a button that causes ProcessPhoenix to be invoked

I would expect the app to relaunch with only A showing, but B is relaunched instead. I tried specifying the Intent for A but even that doesn't work. Testing on an Emulator, API 28. Am I doing something wrong or is this a bug? I've combed over the code and can't figure out why this is happening.

edenman avatar Jan 11 '20 03:01 edenman

Don't have much bandwidth here. Maybe send a PR to the sample to create a similar situation so we can repro?

JakeWharton avatar Jan 14 '20 05:01 JakeWharton

You should use finishAndRemoveTask as mentioned here: https://stackoverflow.com/a/27765687/1761406

Shirane85 avatar Feb 26 '20 13:02 Shirane85

Kinda +1 for this. Although our problem is that app is crashing just after rebirth. Our scenario is: HomeActivity -> PreferenceActivity1 -> PreferenceActivity2.

In PreferenceActivity2 we call triggerRebirth() with custom Intent pointing to HomeActivity. The problem is that after the rebirth, the PreferenceActivity1 is for some reason recreated without UI, thus crashing the app, because we call getPreferenceScreen()(which is null) from onResume().

We adjusted ProcessPhoenix to call finishAffinity() instead of finish(), which seems to be working.

marosseleng avatar Apr 20 '20 10:04 marosseleng

Can you update our sample to replicate the problematic behavior in a PR? And perhaps include the fix?

JakeWharton avatar Jun 25 '21 20:06 JakeWharton

Kinda +1 for this. Although our problem is that app is crashing just after rebirth. Our scenario is: HomeActivity -> PreferenceActivity1 -> PreferenceActivity2.

In PreferenceActivity2 we call triggerRebirth() with custom Intent pointing to HomeActivity. The problem is that after the rebirth, the PreferenceActivity1 is for some reason recreated without UI, thus crashing the app, because we call getPreferenceScreen()(which is null) from onResume().

We adjusted ProcessPhoenix to call finishAffinity() instead of finish(), which seems to be working.

I am a launcher app. I had a problem in Android 7.1, when I restarted the app using the "triggerRebirth" method, a black screen appeared and the activity never reopened.

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            finishAffinity();
        } else {
            finish();
        }

Thanks for your answer, it solved my problem.

Fly-Felix avatar Jun 14 '24 02:06 Fly-Felix

Kinda +1 for this. Although our problem is that app is crashing just after rebirth. Our scenario is: HomeActivity -> PreferenceActivity1 -> PreferenceActivity2. In PreferenceActivity2 we call triggerRebirth() with custom Intent pointing to HomeActivity. The problem is that after the rebirth, the PreferenceActivity1 is for some reason recreated without UI, thus crashing the app, because we call getPreferenceScreen()(which is null) from onResume(). We adjusted ProcessPhoenix to call finishAffinity() instead of finish(), which seems to be working.

I am a launcher app. I had a problem in Android 7.1, when I restarted the app using the "triggerRebirth" method, a black screen appeared and the activity never reopened.

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            finishAffinity();
        } else {
            finish();
        }

Thanks for your answer, it solved my problem.

Last week I said that I solved the problem of not being able to restart after changing it this way. In fact, in the end, I tested that it still cannot restart under certain conditions.

So I made the following changes:

        binding.reboot.setOnClickListener {
            requireActivity().finish()
            ProcessPhoenix.triggerRebirth(requireContext())
        }

Use requireActivity().finish() before executing triggerRebirth so that even if I don't modify the ProcessPhoenix source code to add finishAffinity(), I can restart the app in any situation.

Fly-Felix avatar Jun 17 '24 01:06 Fly-Felix