我正在尝试构建一个我正在同时播放视频和图像的应用程序。每隔一小时左右,该应用程序必须从互联网上下载材料。所以为了使用新材料,我试图让它重新启动。我已经实现了一个可运行文件,并将下载和重新启动的代码放在运行方法中。问题是应用程序在启动后很快就冻结了-
synchronized public void run() {
download("http://www.justieltsshaddi.com/pankaj/list.txt",
Environment.getExternalStorageDirectory() + "/alpha/list.txt");
File beta = new File(Environment.getExternalStorageDirectory()
+ "/beta/");
File betalist = new File(beta + "/list.txt");
File alpha = new File(Environment.getExternalStorageDirectory()
+ "/alpha/");
File alphalist = new File(alpha + "/list.txt");
if (alphalist.lastModified() == betalist.lastModified()) {
return;
}
try {
FileReader inAlpha = new FileReader(alphalist);
BufferedReader br = new BufferedReader(inAlpha);
String s;
Toast.makeText(this, "Starting Download...", Toast.LENGTH_SHORT)
.show();
while ((s = br.readLine()) != null) {
download("http://www.justieltsshaddi.com/pankaj" + "/" + s,
Environment.getExternalStorageDirectory() + "/alpha/"
+ s);
}
// stop the activity to rename folders
Toast.makeText(this, "Download done. Restarting...",
Toast.LENGTH_SHORT).show();
Log.d("Pankaj", "Download Done");
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
Log.d("Pankaj", "MainActivity Killed");
// rename alpha to beta
deleteSubFolders(beta.toString());
alpha.renameTo(beta);
if (!alpha.exists()) {
alpha.mkdir();
}
File upper = new File(alpha + "/upper/");
if (!upper.exists())
upper.mkdirs();
File lower = new File(alpha + "/lower/");
if (!lower.exists())
lower.mkdirs();
// restart the activity
overridePendingTransition(0, 0);
startActivity(intent);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
任何帮助表示赞赏。提前致谢。