Niru
Niru

Reputation: 163

Can I call finish() of an activity through adb shell command?

I want to invoke the onDestroy() callback of an activity through adb command. Can anyone let me know if there is a way to call finish() of an activity through adb shell command?

Upvotes: 11

Views: 8854

Answers (2)

HedeH
HedeH

Reputation: 3034

Unless you have overriden onBackPress for that activity,

You can use the back button key event to destroy the activity:

adb shell input keyevent 4

SOURCE

You also have

adb shell am force-stop "package.name" 

and

adb shell am kill "package.name" 

But those commands will not trigger onDestroy, they will just kill the process, Plus the am kill only kills processes that are safe to kill (Meaning a process with no running services or activities).

Upvotes: 7

ammcom
ammcom

Reputation: 1034

You can finish your app which will close the activity:

adb shell am kill 'your package name'

Upvotes: 0

Related Questions