Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

adb

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?

like image 521
Niru Avatar asked Sep 12 '18 11:09

Niru


People also ask

How do you finish an activity?

On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.

How do I launch an activity from adb?

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.

How do I end an adb session?

To stop the adb server, use the adb kill-server command. You can then restart the server by issuing any other adb command.

What are adb shell commands?

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.


1 Answers

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).

like image 59
HedeH Avatar answered Sep 22 '22 14:09

HedeH