Removing App from Recent Apps in android using adb shell command - android

I want to remove an application from recent apps using shell command. please help me with a working solution.
Thanks
Balaji

You can not remove from the recent but you can kill your application using command line,
kill [options] Kill all processes associated with (the app's package name). This command kills only processes that are safe to kill and that will not impact the user experience.
Options are:
--user | all | current: Specify user whose processes to kill; all users if not specified.
http://developer.android.com/tools/help/shell.html for your reference.
I hope this will help you.

Related

strace shell command issue in Android

I'm building a monitor app, which runs in background and logs the system calls executed by currently running application using the strace command.
String cmd="strace -p "+processID+" -o /mnt/sdcard/traceFile_"+processID+".txt";
Runtime.getRuntime().exec(cmd);
Here processID is the PID of currently running process which is got from some other method implemented. It logs the system calls of the first app it monitors properly with all executed system call information. But when a new app is started(second one onwards), the processID is updated correctly, but the file traceFile_processID is written as an empty file.
I'm not able to figure out why its happening. Is it because the strace execution of first app monitored still there?? If so how I can execute a ^C to terminate that session and start a new one as in adb shell command prompt?? Plz help me.....
If you want to "^C" as you say, what you're really asking for is how to raise the signal called SIGINT to the given processID. You can do that simply by kill(processID, SIGINT); - this is equivalent to pressing Ctrl-C on the keyboard for the target process.

How to know when the user has closed the Android application?

Is there any way of finding when an application is closed (either by user or system) i.e the application can only be restarted by the user by pressing the application launcher icon.
I think it is only possible if Android system broadcast any Intent when a name of a process is removed from getRunningAppProcesses().
I have read all the possible Q&A on the SO and the question is not related with the ActivityLifecycle.
Generally, waiting for a user to "exit" an app is a bad idea, since:
The user never actually exists the app, they simply leave it on the activity stack and come back to it later.
A user might do anything during your database update, such as reenter the app.
You can't really detect this without very hacky solutions; this is by design of the API, because you shouldn't need to do these kinds of things.
Because of this, I think any solution based on waiting for the app to "die" is a bad one. Instead, you should come up with a solution that respects the semantics of the application. For example, if you are entering data in one of its content providers then it should handle consistency (across fragments in the app, for example).
Hmm.. You can manually monitor /proc on the filesystem to see if the process id is present for the application you care about.
From your terminal window try the following. For example :
> MYPID=(`adb shell ps | grep com.mydomain.myapp | awk '{print $2}'`)
> adb shell [ -d /proc/$MYPID ] && echo "PID $MYPID Exists"
Replace com.mydomain.myapp with your apps package name
There are several apps available to monitor processes on android.
Take a look at http://code.google.com/p/android-os-monitor/
The android-os-monitor project uses a JNI layer to implement the interaction with /proc
http://code.google.com/p/android-os-monitor/source/browse/OSMonitor/jni/process.c?repo=osmonitor
http://code.google.com/p/android-os-monitor/source/browse/OSMonitor/src/com/eolwral/osmonitor/JNIInterface.java?repo=osmonitor
http://code.google.com/p/android-os-monitor/source/browse/OSMonitor/src/com/eolwral/osmonitor/processes/ProcessList.java?repo=osmonitor

Accept 'Force Close' dialog via ADB shell

I'm trying to figure out how (or if it's possible) to accept the 'Force Close' dialog via the adb shell when an Android app crashes with a hard error (specifically out_of_memory). I'm hoping to basically loop an app with a bash script, so when it crashes I want to start it running again. The missing step here is that I can't simulate pressing the 'Force Close' button that shows up in the middle of the dialog.
At the same time, the process doesn't seem to actually be running (trying to kill the PID doesn't work), so it's a bit of a weird situation because it seems to have already stopped, but launching it again (via adb shell am ...) just gives me 'current task has been brought to the front'.
Any thoughts would be appreciated!
+1 to DarkXphenomenon for the UncaughtExceptionHandler.
However to kill the process you should use am:
am force-stop: force stop everything associated with <PACKAGE>.
am kill: Kill all processes associated with <PACKAGE>. Only kills.
processes that are safe to kill -- that is, will not impact the user
experience.
for example:
adb shell am force-stop <YOUR.PACKAGE.NAME>
If it is your own app, you can add an UncaughtExceptionHandler and not show the force close dialog. If not, the following might work.
You can also kill the process from adb. (Credit)
adb shell kill $(adb shell ps | grep YOUR.PACKAGE.NAME | awk '{ print $2 }')
After that, you can use adb shell am ... to respawn the process.

Stop running application with ADB

is there a simple way to stop a running application using ADB.
Szenario:
Working on App
Have a script which uploads, installs and starts App on change
Problem:
Currently running version gets killed (not shutdown), which make testing cleanup very hard. Option would be to "do cleanup in between", like after a certain time, but I would prefer to do it in the correct location (so like with the OS, as long as the App is still running, so need to save value, as soon as the OS tells me e.g. memory low or calls onDestroy, I want to save stuff)
Chris
I'm not aware of a way to do this. I was hoping there might be a way to send an intent to tell the app to exit using adb shell e.g.
adb shell am start -a [intent] -n [class]
However, I found that somebody asked this question on a Google forum but they haven't got an answer:
http://groups.google.com/group/android-platform/browse_thread/thread/3fd02d01c6c3b41a/56814e518503efd6

How do Task Managers kill apps?

First of all I know it's bad to use a task manager/killer in Android and all that, but what I was wondering is how do task managers like Advanced Task Killer kill other applications?
I wanted to develop a simple application that would do this, just for the learning experience.
I tried executing the Linux command kill pid from my application but it didn't work, maybe it requires root?
So, how do I accomplish this from my application? I have a simple ListActivity that shows the currently running tasks and when a user long-presses an item I want to kill that task.
You can send the signal using:
Process.sendSignal(pid, Process.SIGNAL_KILL);
To completely kill the process, it's recommended to call:
ActivityManager.killBackgroundProcesses(PackageName)
before sending the signal.
slayton has good answer in this question.I add this detail to his answer:
- when you use ActivityManager.killBackgroundProcesses(PackageName) , you can not kill foreground process.
I saw these open sources project link in K_Anas'answer to this question:
- github repository
- code.google
try this,
android.os.Process.killProcess(pid)
that will work...
1- Add to manifest
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
2 - In your code
Runtime.getRuntime().exec("adb shell killall com.example.app");
Note : Your app needs to have access to adb shell system/app (root permission)

Categories

Resources