How do I tell if an android activity is finished f

2019-05-06 21:54发布

问题:

In our testing, I want to use a script to run a number of android activities. I can use an adb shell start activity command to start these activities. Is there a way, using an adb command, to tell when an activity finishes? The script needs to know when the first activity is done before issuing the next adb start activity command.

回答1:

I did something recently where I wanted a bash script to run an adb command and show/wait until it was finished. This is what worked for me:

./adb shell am start -W -n com.android.settings/.ApplicationSettings

The script then waited for the applications menu to load before continuing. Not sure how this would work for a longer process but it's worth a shot.



回答2:

If you can control the source of the applications you are monitoring, do what Daniel has suggested in the comments to the question. But if you can't - try executing dumpsys activity activities and see if you could find the info you are looking for there. Take a look at the Running activities section and see if your activity disappears from the list when finished.