11

Is it possible to push an application to the background through an adb command? I have an application which calls google navigation and I want push google navigation to the background using an adb command. I don't want to just go back to the home screen, I want make sure the app which called google navigation remains on the foreground. So far I have:

adb shell am force-stop com.google.android.apps.maps

But the above command force stops the process instead of pushing to background.

RagHaven
  • 4,156
  • 21
  • 72
  • 113
  • 3
    Um, why not just bring your application back to the foreground, by calling `startActivity()` on one of its activities? – CommonsWare Jun 24 '13 at 23:58

3 Answers3

17

You can send a Home key event via adb, pressing Home should put an Activity to the background:

adb shell input keyevent 3

from the docs:

public static final int KEYCODE_HOME Added in API level 1

Key code constant: Home key. This key is handled by the framework and is never delivered to applications. Constant Value: 3 (0x00000003)

possible values: http://developer.android.com/reference/android/view/KeyEvent.html

more to-the-point list: ADB Shell Input Events

Community
  • 1
  • 1
n611x007
  • 8,952
  • 8
  • 59
  • 102
  • 1
    if it counts (in addition to the upvote), I believe your solution is good. It is closer to what the question asks than the accepted answer. – shalafi Jun 09 '15 at 13:47
  • @shalafi (I normally don't comment like this but) thanks man I'm glad if it's useful to you! – n611x007 Jun 09 '15 at 14:38
1

As CommonWare commented, Instead pushing the other app to background you can bring your app to foreground by calling startactivity and by setting appropriate flags.

Intent i = new Intent(context, YourActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
stinepike
  • 54,068
  • 14
  • 92
  • 112
  • I had to change Intent.FLAG_ACTIVITY_REORDER_TO_FRONT to Intent.FLAG_ACTIVITY_NEW_TASK since I was calling it from a non activity class. – RagHaven Jun 25 '13 at 22:50
  • I have no app. I just want to push another app from adb to the background, I don't care what gets into the foreground as long as it's a different one. Any way? – n611x007 Jul 09 '14 at 18:38
1

I use appium_liband I write background_app 8 to minimize and have the application running in the background. 8 is the number of seconds you will want to keep it minimized.

Emjey
  • 2,038
  • 3
  • 18
  • 33