How to see if a sub-activity was started or not


I'm writing a unit test for an Android application.

I'd like to see if clicking a button will open a correct sub-activity or not.

There is a main activity, and within it, there are two buttons, each of which launches a sub activity when clicked.

I think the problem happens because these are sub-activities.

So, this is the test method in my unit test case.

@UiThreadTest public void testActivityLaunch() { //Launches a subActivity theButton.performClick(); ActivityManager am = (ActivityManager) mActivity.getSystemService(Service.ACTIVITY_SERVICE); List<RunningAppProcessInfo> procInfos = am.getRunningAppProcesses(); List<ActivityManager.RecentTaskInfo> processes = am.getRecentTasks(5, ActivityManager.RECENT_WITH_EXCLUDED); }

I set up a breakpoint and looked into both procInfos and processes, and I can't see the name of the subActivity.

I created a similar method in the app that is being tested, and I still couldn't see the name of the sub-activity in the list even after it was launched.

I just need an access to the name of sub-activity in the process list just to know if a button click has launched it properly or not. Is there any other way to test this?

I'd not like to use any other frameworks, such as Robotium, other than what's provided in ADK.

EDIT: I'm not sure if this is a sub-activity after all. I just read an article saying it is considered a sub-activity if it is started with startActivityForResult(). On the button click listener I'm starting it with startActivity().


You need an <a href="http://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html" rel="nofollow">ActivityMonitor</a> to wait for started Activities. A very similar example is featured in <a href="http://www.packtpub.com/android-application-testing-guide/book" rel="nofollow">Android Application Testing Guide</a>.


  • Linear function
  • OAuth and Java (connecting to GMail) [closed]
  • Twitter Authentication through Android's AccountManager classes
  • google Plus Login Failed error code 17 android
  • How can I correct Fatal Exception - Async Task [duplicate]
  • How can I use the Note To Self intent from Google Now?
  • cannot be cast to android.content.pm.PackageInfo on click in my listview
  • Android TextView, setText using multiple variables concated together
  • cannot find symbol class DaggerAppComponent or cannot find symbol class DaggerActivityComponent
  • UknownHostException while trying to post a message to facebook
  • how to check if the click is Performclick or not
  • Android Twitter4j getting error while retweet or send message
  • Firebase Dynamic Link ShortUrl not working in Android
  • Intent Filter for handling address press in Contact?
  • Unity Android with AppCompat Rejecting re-init on previously-failed class java.lang.Class
  • Android NFC: can we use intent filter with mime type? (android 2.3.3)
  • Force Down error in MapView
  • Checking if an array in C is symmetric
  • c# open webrowser in many tab
  • Bypass multiple inheritance in Java
  • how to find common suffix in java by using method
  • Display java JPanel in a JFrame
  • onBackPressed() not being executed
  • iOS: Detect app start via notification press
  • how to adjust image in a panel in Java swing?
  • How to access EntityManager inside Entity class in EJB3
  • how to do an event when i swipe from fragment to the other
  • JFileChooser in front of fullscreen Swing application
  • HTML download movie download link
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Possible to stop flickering java tooltip in heavyweight mode?
  • sending/ receiving email in Java
  • Eraser for UIBezierPath
  • Suggestions to manage Login/Logout transitions
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?