android 退出程序
16lz
2021-01-23
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 Codepublic 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
更多相关文章
- imageButton被边框包围的原因、解决办法
- Android 5.0使用android:onClick属性出现崩溃的原因及解决方案
- android 工程里缺少 R.java 文件原因和解决方法
- 将服务器端字符读取至android的文本控件,换行符变成了黑方块的原
- Android build失败 原因总结:
- android 4.3之前的版本 播放hls获取不到总时长的原因
- Android DataBinding 找不到生成的binding类的原因
- android ANR产生原因和解决办法