Android中完全退出APP的方法

来源:互联网 发布:iphone手机必备软件 编辑:程序博客网 时间:2024/04/29 16:42
1.在,要执行退出的activity中进行相关配置
 
public static final String ALL_EXIT = "COM.DEVDIV.TEST.EXIT";// 申明通知
 
 【使用】
public static void fullExit(Context context) {
Intent intent = new Intent(context, WelcomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(APP.ALL_EXIT);
context.startActivity(intent);
}
 
 
2.在初始页面重写方法
 
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.getAction().endsWith(APP.ALL_EXIT)) {
finish();
System.exit(0);
}
}
 
@Override
protected void onDestroy() {
super.onDestroy();
finish();
System.exit(0);
}
 
3.在配置文件中初始Activity中添加配置【android:launchMode="standard"】
 
 <activity
            android:name=".WelcomeActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
原创粉丝点击