3

After deploying a new APK for a system app, is there a way to restart the app process without rebooting the device?

Non-system apps are managed with the Activity Manager through the am command. There are options like start, restart, force-stop, as well as commands against services, like startservice or stopservice.

I have mainly read and tried around the Activity Manager, and I am missing something. Right now, I just rely on the time-consuming brutal reboot command. Posts on installing system apps also use reboot only, as far as I found.

Great and timely feedback mention the very commands I tried, but when they work, they are in "force" mode. I did not check the source code, but it usually means something akin to kill -s SIGKILL, and I wonder whether that is really necessary to go that far.


Some sample outputs (thanks everyone for comments!):

(note, I have indented the command output for readability)

Restarting with restart

$:/ # am start com.android.email
    Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] pkg=com.android.email }
$:/ # ps | grep email
    u0_a30    1436  117   705400 32128 ffffffff 4006b954 S com.android.email
$:/ # am restart com.android.email
    Restart the system...
    android.os.DeadObjectException
    at android.os.BinderProxy.transact(Native Method)
    at android.app.ActivityManagerProxy.restart(ActivityManagerNative.java:4647)
    at com.android.commands.am.Am.runRestart(Am.java:1410)
    at com.android.commands.am.Am.onRun(Am.java:308)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
    at com.android.commands.am.Am.main(Am.java:78)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
    at dalvik.system.NativeStart.main(Native Method)
$:/ # ps | grep email
$:/ # #=> Process was killed anyway
$:/ # am start com.android.email #=> Works again, but the previous error...

Restarting with force-stop

$:/ # am start com.android.email
$:/ # ps | grep email
    u0_a30    2680  1506  706404 31668 ffffffff 40059954 S com.android.email
$:/ # am force-stop com.android.email
$:/ # ps | grep email
$:/ # #=> Process killed
$:/ # am start com.android.email #=> Works again, but it was *forced* kill!

Some context and idiosyncrasies: My particular case is a custom system app (in /system/priv-app) that exposes a service, no activity. I am used to rely on am startservice and am stopservice to manage non-system processes. It does not work properly for system apps (read: "I don't know how to do it" :-) ). All this is on Android 4.4.2, API level 19.

  • 1
    Not really an answer, but faster than a complete reboot it should be to do a soft reboot (i.e. kill the system server). Though I don't know how to do that from the command line (I've normally used the boot menu for that ;) my guess is you simply use the kill command on its process once you've identified that (ps | grep system_server should help you find its PID): kill $(ps | grep system_server | awk '{print $2}'). That said: if you can identify the PID of that app, it should work the same way (but might have side effects). – Izzy Mar 8 '16 at 7:01
  • @Izzy Isn't it something like busybox killall system_server. I used that command before in an app I made. – Thomas Vos Mar 8 '16 at 7:24
  • 1
    Yeah I didn't expected am restart to work, but am force-stop & am start should. What happens when you try it? – Matthew Read Mar 8 '16 at 8:22
  • 6
    @EricPlaton : I can give my assurance that a system app can be force-stopped completely and one of its component can be started from scratch again. My answer here can show you that (hint: com.android.vending is a system app). // Can you precisely tell us what in that app are you trying to restart? am start -S COMPONENT would force-stop the app and then start your app's component. am force-stop PACKAGE and then am start or am startservice can help you as well. – Firelord Mar 8 '16 at 11:45
  • 1
    I'll have to take a peek around the source code and see whether the Android system itself does a kill when updating an app. – Matthew Read Mar 9 '16 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.