• 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

  • 相关阅读:
    SMTP协议原始命令码和工作原理[转]
    VC++ SMTP协议电子邮件传送剖析
    C++编译模式(转)
    IE6下select标签覆盖div的完美解决办法
    星级评论插件
    CSS Reset CSS Framework
    if判断IE浏览器的类型
    通过Prototype属性添加Array删除重复数据方法
    Javascript性能优化
    我自己的Javascript 库,封装了一些常用函数
  • 原文地址:https://www.cnblogs.com/xiaobuild/p/2469909.html
Copyright © 2020-2023  润新知