android - Robolectric onCreate with savedInstanceState that contains ViewHierarchyState, FragmentManagerState -


using robolectric, how can test recreation of activity simulate case android recreating activity in response button (after activity destroyed android ram pressure)?

on device, steps reproduce recreation of activity are:

  • turn on "do not keep activities" in developer settings
  • navigate activity in app
  • use notification bar bring settings activity or other activity on top of activity, cause activity destroyed android simulation of ram pressure
  • use button dismiss overlapping (settings) activity

as result of last step button, activity gets oncreate() non-null saveinstancestate contains information including instance of bundle key "android:viewhierarchystate" and, if fragments used, instance of fragmentmanagerstate key "android:support:fragments".

how can simulate in robolectric? assume activitycontroller.create(bundle) if can set bundle appropriately.

thanks!

my pair figured out! use saveinstancestate() ask android populate bundle need:

    activitycontroller<searchactivity> controller = activitycontroller.of(searchactivity.class);     controller.create().start().resume().visible().get();     bundle outstate = new bundle();     controller.pause().saveinstancestate(outstate).stop();      controller = activitycontroller.of(searchactivity.class).create(outstate).start().visible();     subject = controller.get();      // create(bundle) method called complete view hierarchy , fragment information 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -