强制关闭应用程序[英] force close the application

本文是小编为大家收集整理的关于强制关闭应用程序的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我是 Android 新手,遇到了一个问题.

我想知道如何以编程方式强制关闭应用程序并重新启动它.我正在尝试这个,因为我真的被 OutOfMemmoryError 困住了,我想释放内存并再次重新启动应用程序.

如果我错了,请指导我.

推荐答案

重新启动应用程序以避免或修复 OutOfMemoryExceptions 是一个非常糟糕的主意.你应该开始解决你的记忆问题本身,而不是在它们发生时做一些奇怪的事情.

你应该治愈疾病而不是治疗症状.

其他推荐答案

要强制关闭应用程序只需调用:

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

关于 OutOfMemoryError - 处理此类错误的最佳位置方法 Application.onLowMemory(),例如:

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

其他推荐答案

不知道能不能手动强制关闭,但是很错误.

尝试检查您的代码并找出 OutOfMemoryException 的位置.另请检查这个问题 指导.

本文地址:https://www.itbaoku.cn/post/102729.html

问题描述

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.

推荐答案

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.

其他推荐答案

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

其他推荐答案

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.