How to quit android application programmatically

前端 未结 30 2058
迷失自我
迷失自我 2020-11-22 03:06

I Found some codes for quit an Android application programatically. By calling any one of the following code in onDestroy() will it quit application entirely?

30条回答
  •  温柔的废话
    2020-11-22 03:27

    We want code that is robust and simple. This solution works on old devices and newer devices.

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            getActivity().finishAffinity();
        } else{
            getActivity().finish();
            System.exit( 0 );
        }
    

提交回复
热议问题