0

I'm doing an Android Instrumentation Test Case using the class ActivitiyInstrumentationTestCase2. I've displayed an dialog using the Activity context.

Activity.java

Dialog customDialog = new Dialog(this);

Is there any way to retrieve the dialog using the activity context in the test case activity?

Ophitect
  • 543
  • 4
  • 18

1 Answers1

0

Based on the source code, you can use the method getOwnerActivity() to get the Activity that was passed to the constructor.

http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/app/Dialog.java/?v=source

It might be helpful to get the name using getAssociatedActivity() which returns a ComponentName (which is helpful if you have several layers of components that use the Activity context before creating the Dialog

Jim
  • 10,172
  • 1
  • 27
  • 36