process p = Runtime.getRuntime().exec() is running even when I uninstall the application
I have observed very strange behavior in my application.
My application is having one Service and one Activity , In my Service part of my application I need to execute LogCat command which will dump its output to the text file which is stored in SD card of the devic开发者_运维知识库e.
To run the LogCat command in my Service I have used the below code:
Process p = Runtime.getRuntime().exec("logcat -v time -f /mnt/sdcard/log.txt &");
The above code is running in background and so far I have achieved what I need.
But the above command is even running after I uninstall my application from the device. My log.txt file in the SD card is keep on increasing.
I have checked the "Applications -> ManageApplications -> RunningServices" but there's no my Service is running.
Please help me how to stop my background process when I uninstalled my application.
This issue is very strange but It's happening.
These symptoms gone away only I rebooted the device.
You are launching a new process, so it is not tied to your current process at all. It will not be killed when your app is killed. I know of only two options here: 1) Run logcat with -d (I believe), which will have it exit when it reaches the end of the buffer. Logcat by default runs until it is closed, which if you just want a dump of the logs you should use -d. 2) If you don't want a dump, but want it to keep streaming to a file, then there is no clean way to kill it. The only way I know how is to exec ps and then read the console buffer and parse it to find the pid of your logcat process and then kill the process using Process.killProcess.
You can remember the process returned by Runtime and terminate it when uninstalling the app.
精彩评论