0

I am running an app from ADB shell like this:

adb shell am start -n mypackage/.MainActivity

I need to terminate the app automatically after 10 seconds and start another application. I am trying to do something like this:

adb shell timeout -t 10 am start -n mypackage/.MainActivity

But unfortunately this does not work.

Output:

/system/bin/sh: timeout not found

Is there any way to make this work?

Ahsan Tarique
  • 581
  • 1
  • 11
  • 22

2 Answers2

1

Use following

start adb shell am start -n mypackage1/.MainActivity
timout /t 10
kill  mypackage1
start adb shell am start -n mypackage2/.MainActivity

More Info here

Ahsan Tarique
  • 581
  • 1
  • 11
  • 22
Ratul Sharker
  • 7,484
  • 4
  • 35
  • 44
  • i'm running it from windows 10. tried `timeout 10` instead of `sleep 10`. but it still does not work. `timeout 10` does not execute unless the first one completes. – Ahsan Tarique Nov 13 '16 at 16:59
  • have you tried the timeout after starting the intent ? i.e the flow should be start the package, pause a certain time, kill the started package, start another package. – Ratul Sharker Nov 13 '16 at 17:19
  • yes i tried your script, just changing the `sleep 10`. The problem is command window waits for the first process to end before executing `timeout 10`. so it waits forever. – Ahsan Tarique Nov 13 '16 at 17:51
  • could you give it a try, starting the first application in a separate process which will run asynchronusly ? http://stackoverflow.com/questions/1449188/running-windows-batch-file-commands-asynchronously – Ratul Sharker Nov 13 '16 at 17:59
  • hey, i was exactly looking at this and edited your code. And just now I saw your comment. Thanks, I'm marking this as the correct answer to my question. – Ahsan Tarique Nov 13 '16 at 18:09
0

You can use sleep command running on the device itself:

adb shell "am start -W -n mypackage1/.MainActivity; sleep 10; am force-stop mypackage1"
adb shell "am start -W -n mypackage2/.MainActivity"

It seems that the app you are trying to start/stop is not designed properly. In this case do:

adb shell "(sleep 10; am force-stop mypackage1) & am start -n mypackage1/.MainActivity"
adb shell "am start -n mypackage2/.MainActivity"
Alex P.
  • 30,437
  • 17
  • 118
  • 169