JakeWharton / ProcessPhoenix

Process Phoenix facilitates restarting your application process.
Apache License 2.0
2.03k stars 132 forks source link

Killed app relaunches same Activity instead of default Activity #37

Open edenman opened 4 years ago

edenman commented 4 years ago

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

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.

JakeWharton commented 4 years ago

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

Shirane85 commented 4 years ago

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

marosseleng commented 4 years ago

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.

JakeWharton commented 3 years ago

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

Fly-Felix commented 5 months ago

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 commented 5 months ago

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.