12

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.

1
  • 3
    Um, why not just bring your application back to the foreground, by calling startActivity() on one of its activities? Commented Jun 24, 2013 at 23:58

3 Answers 3

18

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

2
  • 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
    Commented Jun 9, 2015 at 13:47
  • @shalafi (I normally don't comment like this but) thanks man I'm glad if it's useful to you!
    – n611x007
    Commented Jun 9, 2015 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);
2
  • 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
    Commented Jun 25, 2013 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
    Commented Jul 9, 2014 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.