Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Killed app relaunches same Activity instead of default Activity #37

Open
edenman opened this issue Jan 11, 2020 · 6 comments
Open

Killed app relaunches same Activity instead of default Activity #37

edenman opened this issue Jan 11, 2020 · 6 comments

Comments

@edenman
Copy link

edenman commented Jan 11, 2020

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.

@JakeWharton
Copy link
Owner

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

@Shirane85
Copy link

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

@marosseleng
Copy link

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
Copy link
Owner

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

@Fly-Felix
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants