android 退出系统

/**
 * 
 */
package com.szkingdom.android.phone.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.webkit.CookieManager;

import com.szkingdom.activity.basephone.ActivityStackMgr;
import com.szkingdom.android.phone.R;
import com.szkingdom.android.phone.widget.KdsDialog;
import com.szkingdom.android.phone.widget.KdsSureDialog;
import com.szkingdom.common.android.base.OriginalContext;
import com.szkingdom.common.android.base.Res;
import com.szkingdom.commons.log.LogcatHelper;
import com.szkingdom.android.phone.KdsAgentMgr;
import com.szkingdom.android.phone.widget.KdsDialog.OnClickButtonListener;

/**
 * @author duminghui
 * 
 */
public class ExitConfirm
{
    private static KdsDialog mKdsSureDialog;

    public static final void confirmExit(final Context context)
    {
        
       mKdsSureDialog = new KdsDialog(context,"提示",Res.getString(R.string.kds_exit_dialog_content), new OnClickButtonListener() {
            
            @Override
            public void onClickButton(View view) {
                // TODO Auto-generated method stub
                
            }
        }, new OnClickButtonListener() {
            
            @Override
            public void onClickButton(View view) {
                if(mKdsSureDialog != null && mKdsSureDialog.isShowing()){
                    mKdsSureDialog.dismiss();
                    finishProcess(context);
                }
            }
        });
              mKdsSureDialog.show();
    }

    /**
     * 结束整个进程
     * @param context
     */
    public static void finishProcess(Context context){
        //友盟统计接口方法,如果开发者调用 Process.kill 或者 System.exit 之类的方法杀死进程,
        //请务必在此之前调用此方法,用来保存统计数据
        KdsAgentMgr.onKillProcess(OriginalContext.getContext());
        //清除所有cookie
        CookieManager.getInstance().removeAllCookie();
        LogcatHelper.getInstance(context).stop();  
        ActivityStackMgr.exitActivityHistory();
        Activity activity = (Activity) context;
        activity.finish();
        killProcess(context);
    }
    
    private static void killProcess(Context ctxt)
    {
        String packageName = ctxt.getPackageName();
        String processId = "";
        try
        {
            Runtime r = Runtime.getRuntime();
            Process p = r.exec("ps");
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    p.getInputStream()));
            String inline;
            while ((inline = br.readLine()) != null)
            {
                if (inline.contains(packageName))
                {
                    break;
                }
            }
            br.close();
            StringTokenizer processInfoTokenizer = new StringTokenizer(inline);
            int count = 0;
            while (processInfoTokenizer.hasMoreTokens())
            {
                count++;
                processId = processInfoTokenizer.nextToken();
                if (count == 2)
                {
                    break;
                }
            }
            // Log.e(TAG, "kill process : " + processId);
            r.exec("kill -15 " + processId);
        } catch (IOException ex)
        {
            // Log.e(TAG, "" + ex.getStackTrace());
        }
    }


}
 public static List<ISubTabView> activityHistoryWindows = new ArrayList<ISubTabView>();
    public static void exitActivityHistory(){
        try{
            for(int i = activityHistoryWindows.size()-1; i >= 0; i--)
                ((Activity)activityHistoryWindows.get(i)).finish();
            }catch(Exception e){
                
            }finally{
                activityHistoryWindows.clear();
            }
    }

 

你可能感兴趣的:(android 退出系统)