简体   繁体   中英

Force My Activity To Call The onSavedInstance State

I have an android application in which I use two themes. On theme change I need to recreate all the activities and Fragments inside that to be recreated.

The same way our application get recreated using saved instnce state.

Is there any way I can force my Activity to call the saved instance state ? IF it is possible how I can do that ? If not why ? Is there any alternative to Achieve this ?

My current code looks like below.

public static final void restartActivity(final FragmentActivity activity){
    activity.finish();
    activity.startActivity(new Intent(activity, activity.getClass()));
}

The issue with this is the fragment back stack is not getting recreated. Any help would be greatly appreciated.

Your state is not saved because you're creating a new instance of Activity . As a solution, you can pass your state to this new instance as Intent extras and restore state in onCreate from those extras.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM