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

更多相关文章

  1. imageButton被边框包围的原因、解决办法
  2. Android 5.0使用android:onClick属性出现崩溃的原因及解决方案
  3. android 工程里缺少 R.java 文件原因和解决方法
  4. 将服务器端字符读取至android的文本控件,换行符变成了黑方块的原
  5. Android build失败 原因总结:
  6. android 4.3之前的版本 播放hls获取不到总时长的原因
  7. Android DataBinding 找不到生成的binding类的原因
  8. android ANR产生原因和解决办法

随机推荐

  1. Android(安卓)icon 不同屏幕下尺寸
  2. Android修改默认打开WLAN随时都可扫描
  3. 解决Android Studio报的警告:Resource IDs
  4. Android 限制EditText输入小数点后面位数
  5. Android中ProgressBar用法简单实例
  6. Android获取字体高度和设置行高
  7. android binder机制之——(创建binder服务
  8. android 5.0后矢量图形
  9. android中sqlite的使用
  10. android 检查网络状态