I tried the test:
private void checkMainActivityIsStarted() { activity.showMainActivity(); Intent intent = shadowOf( activity ).getNextStartedActivity(); assertThat( intent ).hasComponent( Robolectric.application, MainActivity.class ); assertThat( intent.getFlags() ).isEqualTo( Intent.FLAG_ACTIVITY_CLEAR_TOP ); }
For the following code:
public void showMainActivity() { Intent intent = new Intent( this, MainActivity.class ); intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP ); startActivity( intent ); }
Does it work for you?
UPDATE
For me, you should split this test into two:
- Activity C returns the correct result code
- Action B, when you call
onActivityResult (this is a public method), activates activity A
For me, it makes no sense to test Android, passing intentions between actions. Correct me if I misunderstood something.
source share