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 ++ ;
}
});
}
I want to start saving my app's log using start button and stop it using stop.
The addLog button is used to see if more lines are being added to log.txt file.
The start button works properly but the problem is it never ends with stop.
Even after pressing stop, when I press addLog button and check the log.txt
file, I see last lines have been added.
What is my fault ?
I need to start the stream, close this activity and take a tour in other activities then come back and shut the logging machine down.