Espresso – Properly clear Activities saved instance states


I am writing espresso tests for my app and having difficulties clearing the app state, state gets saved and this affects other tests and brings flakiness to them.

I use intent rule for starting my activity:

    public final IntentsTestRule<MainActivity> mIntentsTestRule  newIntentsTestRule<>(MainActivity.class, true, false);

My setUp clears everything that I have access to: db, sharedPrefs, custom volatile config.

    public void setUp() {

Sadly I have issues with activity saved instance state, this brings flakiness to my tests since previous states are retained.

Is there a way to clear the saved instance states programmatically for each activity start?


Issue was caused by a memory leak, so the activity was kept without properly clearing it, thanks for the effort, after resolving the leak espresso ran fine.

Answered By – originx

Leave a Comment