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.
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:01busybox killall system_server
. I used that command before in an app I made. – Thomas Vos Mar 8 '16 at 7:24am restart
to work, butam force-stop
&am start
should. What happens when you try it? – Matthew Read Mar 8 '16 at 8:22am start -S COMPONENT
would force-stop the app and then start your app's component.am force-stop PACKAGE
and thenam start
oram startservice
can help you as well. – Firelord♦ Mar 8 '16 at 11:45kill
when updating an app. – Matthew Read Mar 9 '16 at 0:55