android 退出程序

1:

android.os.Process.killProcess(android.os.Process.myPid());  
finish();
System.exit(0);
     

2:
Intent intent=new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
System.exit(0);

PS:使用第二种方式退出 会出现本来下载到sdcard的html文件自动删除,没有搞清楚原因,

知道的同学麻烦告诉我一下。

下载html的方法:

View Code
public static Boolean downHtml(String pageURL, String filePath) {
        StringBuilder pageHTML = new StringBuilder();
        try {
            URL url = new URL(pageURL);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            // connection.setRequestProperty("User-Agent", "MSIE 7.0");
            BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
            String line = null;
            while ((line = br.readLine()) != null) {
                pageHTML.append(line);
                pageHTML.append("\r\n");
            }
            connection.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return FileUtils.writeStringToFile(pageHTML.toString(), filePath) ; 
    }
View Code
    public static Boolean writeStringToFile(String strInput, String pFilePaht) {
        OutputStream out = null;
        File file = new File(getRootPath() + pFilePaht);
        try {
            file.deleteOnExit();
            file = createFile(pFilePaht);
            out = new FileOutputStream(file);
            byte[] bytes = strInput.getBytes();
            out.write(bytes);
            out.flush();
            return true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } finally {
            file = null;
            try {
                if (out != null)
                    out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

http://blog.csdn.net/victoryckl/article/details/6705388

原文地址:https://www.cnblogs.com/xiaobuild/p/2469909.html