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?
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
You can use the start command from Activity Manager (am) a.k.a the adb shell am start -n command (via adb) specifying the app package name and the component name as defined in the manifest. You can add other parameters like ACTION (-a android. intent. action.
To stop the adb server, use the adb kill-server command. You can then restart the server by issuing any other adb command.
Android Shell Commands. ADB is Android Debug Bridge which is a command line utility included with Google's Android SDK. It provides a terminal interface to control your Android device connected to a computer using a USB. ADB can be used to run shell commands, transfer files, install/uninstall apps, reboot and more.
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][1]
You also have the
adb shell am force-stop "package.name"
and
adb shell am kill "package.name"
But those commands will not trigger onDestroy
but kill the process, Plus the am kill
only kills processes that are safe to kill (Meaning a process with no running services or activities).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With