Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ActivityController.close that transitions Activity to destroyed s…
…tate Update ActivityController to implement AutoCloseable, and add a 'close' method that is lifecycle-aware and transitions the underlying Activity to the destroyed state, freeing all resources and making the Activity eligible for gc. This is a convenient way to ensure that ActivityControllers can be freed without having to manage the underlying Activity lifecycles. It also enables ActivityController to be managed using try-with-resources. PiperOrigin-RevId: 410291892
- Loading branch information
1 parent
326991f
commit 936637a
Showing
21 changed files
with
359 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...tric/src/test/java/org/robolectric/android/controller/ActivityControllerRecreateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.robolectric.android.controller; | ||
|
||
import android.app.Activity; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.Robolectric; | ||
|
||
/** | ||
* This test captures an issue where {@link ActivityController#recreate()} would throw an {@link | ||
* UnsupportedOperationException} if an Activity from a previous test was recreated. | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ActivityControllerRecreateTest { | ||
private static final AtomicReference<ActivityController<Activity>> createdActivity = | ||
new AtomicReference<>(); | ||
|
||
@Before | ||
public void setUp() { | ||
createdActivity.compareAndSet(null, Robolectric.buildActivity(Activity.class).create()); | ||
} | ||
|
||
@Test | ||
public void failsTryingToRecreateActivityFromOtherTest1() { | ||
createdActivity.get().recreate(); | ||
} | ||
|
||
@Test | ||
public void failsTryingToRecreateActivityFromOtherTest2() { | ||
createdActivity.get().recreate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.