Search code examples
javaandroidadb

stop adb logcat from running


I am using Runtime.getRuntime().exec("logcat -f log.txt -c"); In my android application.

The problem with is is that it keeps running and never stops.

Is there a command to stop the code/adb command from executing?


Solution

  • You can use this code

    Process proc = Runtime.getRuntime().exec("logcat -f log.txt -c"); // Deletes log.txt
    proc.destroy();//kill the process
    

    You can use proc.destroy(); in onClick() if you want to destroy the logcat when click the button or Handler if you want to destroy it in several seconds or onDestroy() if you want to destroy it when the app destroyed and so on.