how to close android app completely

前端 未结 7 1764
一个人的身影
一个人的身影 2020-12-03 01:59

I created an android application with a logout option in onCreateOptionsMenu. The Logout works perfectly but when I press the back button again it takes me to t

7条回答
  •  天命终不由人
    2020-12-03 02:17

    For Xamarin Users:

    int pid = Android.OS.Process.MyPid();
    Android.OS.Process.KillProcess(pid);
    

    put it in your OnDestroy() function.

    Edit:

    After investigating it thoroughly, I found out that even the above code I wrote does not "Kill" the app totally (deleting it from task manager - "recent apps"). Eventually, after a lot of code tryouts, I managed to figure something out, Overriding "Finish" functions with this code:

    public override void Finish()
        {
            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                base.FinishAndRemoveTask();
            }
            else
            {
                base.Finish();
            }
        }
    

    this is the sole solution for that question!

提交回复
热议问题