アプリケーションを完全に終了する方法で、すべてのActivityとサービスを終了します.

1276 ワード

 , Activity  :
import java.util.LinkedList;
import java.util.List;

import android.app.Activity;
import android.app.Application;

public class MyApplication extends Application {

	private List<Activity> activityList = new LinkedList<Activity>();
	private static MyApplication instance;

	private MyApplication() {
	}

	//  MyApplication 
	public static MyApplication getInstance() {
		if (null == instance) {
			instance = new MyApplication();
		}
		return instance;
	}

	//  Activity 
	public void addActivity(Activity activity) {
		activityList.add(activity);
	}

	//  Activity finish
	public void exit() {
		new MyCommonDialog(" ..") {
			@Override
			protected String doNoUiOpt() {
				// TODO Auto-generated method stub
				for (Activity activity : activityList) {
					activity.finish();
				}
				return super.doNoUiOpt();
			}

			@Override
			protected void doBack(String success) {
				// TODO Auto-generated method stub
				System.exit(0);
				super.doBack(success);
			}
		};

	}

}

読者はexit()メソッドで直接使用できます:for(Activity activity:activityList){activity.finish();}return super.doNoUiOpt(); System.exit(0);
MyCommonDialog , 。