How to close Android application?

后端 未结 22 1204
小蘑菇
小蘑菇 2020-11-22 07:17

I want to close my application, so that it no longer runs in the background.

How to do that? Is this good practice on Android platform?

If I rely on the \"ba

22条回答
  •  孤独总比滥情好
    2020-11-22 07:54

    This is the way I did it:

    I just put

    Intent intent = new Intent(Main.this, SOMECLASSNAME.class);
    Main.this.startActivityForResult(intent, 0);
    

    inside of the method that opens an activity, then inside of the method of SOMECLASSNAME that is designed to close the app I put:

    setResult(0);
    finish();
    

    And I put the following in my Main class:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(resultCode == 0) {
            finish();
        }
    }
    

提交回复
热议问题