I'm trying to restart my activities on Android

Asked 2 years ago, Updated 2 years ago, 159 views

public static void restartActivity(Activity act){

        Intent intent=new Intent();
        intent.setClass(act, act.getClass());
        act.startActivity(intent);
        act.finish();

}

This is the restart method that I created. It doesn't work properly and turns off immediately.

android android-activity

2022-09-22 22:31

1 Answers

Intent intent = getIntent();
finish();
startActivity(intent);

I think you should change the order Like the code above. finish() is called first and the same intend is started anew.

There's a method called Activity.recreate(). reCreate()


2022-09-22 22:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.