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

Activity does not restart if redeclared as singleTop in Manifest #21

Open
build3r opened this issue May 17, 2022 · 0 comments
Open

Activity does not restart if redeclared as singleTop in Manifest #21

build3r opened this issue May 17, 2022 · 0 comments

Comments

@build3r
Copy link

build3r commented May 17, 2022

Both ActivityRecreationHelper and auto activity restart via onResume fails to recreate activity if launchMode is declared as SingleTop

android:launchMode="singleTop"

This is because we are starting activity while the old one is still ongoing.
A simple fix would be finishing activity first before starting the new one.
ex
in ActivityRecreationHelper

   public static void recreate(Activity activity, boolean animate) {
        Intent restartIntent = new Intent(activity, activity.getClass());

        Bundle extras = activity.getIntent().getExtras();
        if (extras != null) {
            restartIntent.putExtras(extras);
        }
        
        activity.finish();
        
        if (animate) {
            ActivityCompat.startActivity(
                    activity,
                    restartIntent,
                    ActivityOptionsCompat
                            .makeCustomAnimation(activity, android.R.anim.fade_in, android.R.anim.fade_out)
                            .toBundle()
            );
        } else {
            activity.startActivity(restartIntent);
            activity.overridePendingTransition(0, 0);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant