Get Current Activity in Espresso android
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: In case of a test that crosses multiple activities, is there a way to get current activity? getActivtiy() method just gives one activity that was used to start the test. I tried something like below, public Activity getCurrentActivity () { Activity activity = null ; ActivityManager am = ( ActivityManager ) this . getActivity (). getSystemService ( Context . ACTIVITY_SERVICE ); List taskInfo = am . getRunningTasks ( 1 ); try { Class > myClass = taskInfo . get ( 0 ). topActivity . getClass (); activity = ( Activity ) myClass .