1

我有一个按钮,单击它时,我在文本视图中显示了一个 logcat。

按钮点击事件 -

findViewById(R.id.button).setOnClickListener(new OnClickListener() {        
@Override
public void onClick(View v) {

Thread mThread = new MonitorLogThread();
    mThread.start();

}

执行执行的线程 -

private class MonitorLogThread extends Thread
    {
         public MonitorLogThread()
         {
             Process process;

             try {
                process = Runtime.getRuntime().exec("logcat UserFragment:I 
                LookUpActivity:I IncomingStream:I *:S");
                br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            } catch (IOException e) {
                e.printStackTrace();
            }         
         }

        @Override
        public void run() {
            try {     

                    Log.i(TAG, "Getting the logs for Logcat");

                    logItems.clear();

                    String line;

                    // Check if it matches the pattern
                    while(((line=br.readLine()) != null) && !this.isInterrupted() && isMonitor){

                    // Filter for your app-line
                    if (line.contains("ClickedEvents:")){
                        System.out.println("the line added......"+line);
                        logItems.add(line);

                    }
                }


            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

问题是我第一次单击按钮时,其中的行textview (and logcat)显示为 -

the line added......User click event
the line added......User click event success
the line added......User click event done
the line added......User click event gone

但是当我第二次单击按钮时,其中的行textview (and logcat)显示为 -

the line added......User click event
the line added......User click event
the line added......User click event success
the line added......User click event success
the line added......User click event done
the line added......User click event done
the line added......User click event gone
the line added......User click event gone

第三添加更多等等......

所以我点击的次数,它重复了它。

可能是什么问题?

4

1 回答 1

1

你得到了重复,因为这个过程永远不会被破坏。process.destroy()用完后再试试。

于 2014-11-27T15:22:31.330 回答