开发者

Android : How to kill programmatically the camera activity running in background?

What happens here is I call the crop image activity and then the camera activity runs in background. When I finish this activity, the camera is still alive at the background. So how can I kill programmatically the camera activi开发者_StackOverflow中文版ty running in background?

Intent newIntent = new Intent(); newIntent.setAction("com.android.camera.action.CROP");

newIntent.setClassName("com.android.gallery", "com.android.camera.CropImage");

newIntent.setData(selectedImage); startActivityForResult(newIntent, IMAGE_CROP


You should let Android handle process lifecycle on its own. When it'd need more memory, it'll kill unused processes. If you kill it yourself, you also risk killing it while the user is using it leading to a bad user experience.


For the same reason users should not use a Task Killer to kill their apps every x minutes, you should not try and kill the camera process either.

Why? The operating system can handle memory management just fine itself. Let it do its thing, it knows what it is doing. Also if you killed a service, it is highly likely it'll re-start itself when killed, causing a drain on power resources. You could also potentially kill a process that is writing to disk and cause corruption.

Also: As CommonsWare pointed out, you're using unreliable private APIs (by hackishly calling the crop intent).


You can get the list of all running processes on the phone via ActivityManager.getRunningAppProcesses and then search for the one you want to kill and then use the method ActivityManager.killBackgroundProcesses to kill the process you want.

Note: You need permission KILL_BACKGROUND_PROCESSES

Note: This method is only supported since android 2.2 (froyo) . On older versions of android you could get yourself a copy of the android source code and search for the right aidl and after that with the help of some magic you can kill processes as well :)

Final note: you should not kill processes unless you really have to as it was mentioned already.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜