int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button start = (Button) findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
String[] cmd = new String[] { "logcat", "-f",Environment.getExternalStorageDirectory()+"/log.txt", "-v", "time" };
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
thread.start();
}
});
Button stop = (Button) findViewById(R.id.stop);
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Runtime.getRuntime().exec("logcat -d");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
Button addLog = (Button) findViewById(R.id.addLog);
addLog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("logTag", Integer.toString(count));
count ++ ;
}
});
}
我想开始使用start
按钮保存我的应用程序的日志并使用stop
. 该addLog
按钮用于查看是否有更多行被添加到log.txt
文件中。该start
按钮可以正常工作,但问题是它永远不会以stop
. 即使按下stop
,当我按下addLog
按钮并检查log.txt
文件时,我看到最后一行已添加。我有什么错?
我需要启动流,关闭此活动并参观其他活动,然后返回并关闭伐木机。