Closing Application and killing it from ram

后端 未结 3 1368
忘了有多久
忘了有多久 2021-01-26 08:41

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

3条回答
  •  甜味超标
    2021-01-26 09:38

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

提交回复
热议问题