Thursday, 21 July 2022

How to recreate an activity in instrumented tests without non-configuration instance being saved?

So here is the deal. I know about ActivityScenario.recreateActivity(). It perfectly reproduces the configuration change case, when all the non-configuration instance from onRetainNonConfigurationInstance() (say ViewModelStore) is passed into the new activity.

But how would one test the case when the activity is fully destroyed and recreated just from the savedInstanceState bundle? I want ViewModelStore to be erased, and ideally, savedInstanceState Bundle to be parceled/unparceled. Similar to when the "Don't keep activities" flag is enabled in Developer options or when the whole process is killed/recreated.

I've looked around but really stuck with this at the moment.



from How to recreate an activity in instrumented tests without non-configuration instance being saved?

No comments:

Post a Comment