force close the application

风流意气都作罢 提交于 2019-12-09 02:03:58

问题


I am new to android and stuck up with an issue.

I want to know how to force close the application programmatically and restart it again. I am trying this because i am really stuck up with OutOfMemmoryError i want to free up the memory and restart the app again.

Please guide me if i am wrong.


回答1:


Restarting the app to avoid or repair OutOfMemoryExceptions is a very bad idea. You should start to work on your memory issue itself instead of just do weird things when they occur.

You should heal the disease instead of medicate the symptoms.




回答2:


To force closing application just call:

android.os.Process.killProcess(android.os.Process.myPid());

About OutOfMemoryError - best place to handle this kind of errors is method Application.onLowMemory(), like:

@Override
public void onLowMemory ()
{
    super.onLowMemory();
    //do smth like freeing reources, etc.
}



回答3:


I don't know if it's possible to force close manually but it's quite wrong.

Try checking your code and find out where the OutOfMemoryException is. Also check this question for guidance.




回答4:


for out of memory set attribute in android manifest android:largeHeap="true" with in application tag



来源:https://stackoverflow.com/questions/4489138/force-close-the-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!