How to force stop my android application programmatically?

前端 未结 6 989
天涯浪人
天涯浪人 2020-11-27 05:59

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

protected void onCreate(Bundle savedInstanceState) {

  this.setCon         


        
6条回答
  •  半阙折子戏
    2020-11-27 06:17

    Another way is

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

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

    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.

提交回复
热议问题