本文介绍了如何强制停止我的Andr​​oid应用程序编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想逼停我的Andr​​oid应用程序,当我点击closeButton。这是我的code。

I'd like to force stop my Android application when I click closeButton. This is my code.

protected void onCreate(Bundle savedInstanceState) {

  this.setContentView(R.layout.layoutxml);

  this.closeButton = (Button)this.findViewById(R.id.close);

  this.closeButton.setOnClickListener(new OnClickListener() {

    @Override

    public void onClick(View v) {

      finish();

    }

  });

}

这结束我的应用程序。如果我去设置 - >应用程序 - >管理应用程序 - > <我的应用程序名称> ,我可以看到的是启用了强制停止按钮。这是否意味着我的申请没有得到完全停止了?

This finishes my application. If I go to Settings -> Applications -> Manage applications -> <my application name>, I can see the 'Force Stop' button is enabled. Does this mean my application was not stopped completely?

我怎样才能彻底完成我的Andr​​oid应用程序,并禁用强制停止按钮,在矿井设置?从我有限的经验,当一个异常(前。NullPointerException异常)发生在应用程序,其异常停止,看起来完全完成,而强制停止按钮看起来禁用。

How can I finish my Android application completely and disable the 'Force Stop' button inthe 'Settings'? From my limited experience, when an 'Exception' (ex. NullPointerException) occurs in the application, it stops abnormally, looks like it finished completely, and the 'Force Stop' button looks disabled.

推荐答案

另一种方式是

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

我不认为这是所有的坏要做到这一点,只要你把的onDestroy这些电话()。 (如果你杀了你的进程在活动中间处理,各种坏事&mdash;喜欢触控对焦进入乙醚和mdash;可能发生)

I don't think it's all that bad to do this, provided you put those calls in onDestroy(). (If you kill your process in the middle of event handling, all kinds of bad things—like the touch focus going into the ether—can happen.)

不过,你需要一个令人信服的理由,从最佳实践,这是刚刚打电话偏离完成(),让OS采取杀死你的进程护理的时候/如果需要

Nevertheless, you need a compelling reason to deviate from best practice, which is to just call finish() and let the OS take care of killing off your process when/if it needs to.

这篇关于如何强制停止我的Andr​​oid应用程序编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:28