在MainActivity
我致电startStoringLogcatOutputToFile()
函数。这是它的实现:
private Thread threadLogCat = null;
private java.lang.Process process = null;
private void startStoringLogcatOutputToFile() {
if (threadLogCat == null || !threadLogCat.isAlive()) {
threadLogCat = new Thread(new Runnable() {
@Override
public void run() {
String fileName = "logcat_" + MappDateTimeHelper.getDateAndTimeForLogFileName() + ".log";
String str = Settings.getInstance().getLogDir();
File outputFile = new File(str, fileName);
try {
process = Runtime.getRuntime().exec("logcat -v time -f " + outputFile.getAbsolutePath());
int res = process.waitFor();
Log.d("aaa", "Process finished with " + res);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
threadLogCat.start();
}
}
在onDestroy
的{{1}}中,我致电MainActivity
。但是在新的日志文件中重新启动我的应用程序后,我从旧文件中看到了部分日志。
我该如何解决这个问题?