How to exit an Android app programmatically?

前端 未结 29 1048
孤城傲影
孤城傲影 2020-11-28 03:54

I am sure this question has been asked number of times because I read a few. My client wants me to put a button into his app where users can click and exit. I have read this

29条回答
  •  囚心锁ツ
    2020-11-28 04:24

    Try this on a call. I sometimes use it in onClick of a button.

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    

    It instead of closing your app , opens the dashboard so kind of looks like your app is closed.

    read this question for more clearity android - exit application code

提交回复
热议问题