关闭应用程序,并从RAM杀死它 [英] Closing Application and killing it from ram

查看:173
本文介绍了关闭应用程序,并从RAM杀死它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想结束我的应用程序,还需要通过点击按钮,从RAM杀死它。 我使用这种方法,但它只是最大​​限度地减少应用程序,并没有 关闭完整的应用程序。该怎么办 ?

 公共无效AppExit()
{

    this.finish();
    意向意图=新的意图(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(意向);
    }
 

解决方案

调用:

  • System.exit(0)
  • Process.killProcess(android.os.Process.myPid());

这两者都是绝对不是的好主意的!

相反,使用活动的结束(); 方法 - 让机器人处理内存管理,它是这样做的。

很好的清理!

如果您不希望您的活动,在活动堆栈显示,标志, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP 通常会足以启动另一个活动。

指定的的Andr​​oidManifest.xml 在你的活动代码,机器人: noHistory =真正的

hi I want to close my application and also want kill it from ram by clicking button. i am using this method, but it just minimize application and didn't close complete app. what to do ?

public void AppExit()
{

    this.finish();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    }

解决方案

Calling:

  • System.exit(0);
  • Process.killProcess(android.os.Process.myPid());

Both of which are definitely not a good idea!

Instead use the activity's finish(); method - let Android handle the cleanup of RAM management, which it is very good in doing so!

If you do not want your activity to be shown in the activity stack, the flags, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP would usually suffice for launching another activity.

OR specify in your AndroidManifest.xml in your activity tag, android:noHistory="true".

这篇关于关闭应用程序,并从RAM杀死它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆