1

I'm developing an application where I'm applying on touch listener to my layout view. I move the layout over screen but that layout doesn't respond well after 10 to 15 secs. Here is my code:

base = (LinearLayout) findViewById(R.id.load);

    base.setOnTouchListener(new OnTouchListener() {                         
        @Override
        public boolean onTouch(View v, final MotionEvent event) {                                     

              int motion = event.getAction();
              int numberOfPointers = event.getPointerCount();
             if (numberOfPointers < 3) {
                     switch (motion & MotionEvent.ACTION_MASK) {

                     case MotionEvent.ACTION_DOWN:                          
                            drag = true;                                                                                           
                     break;

                     case MotionEvent.ACTION_POINTER_DOWN: {
                            drag = false;
                            if (drawWaveForm != null) {
                                   zoom = true;
                            }
                            // initial x1 and x2
                            BitmapDetector.prevX1 = Math.min(event.getX(0), event.getX(1));
                            BitmapDetector.prevX2 = Math.max(event.getX(0), event.getX(1));
                            BitmapDetector.prevY1 = event.getY(0);
                            BitmapDetector.prevY2 = event.getY(1);
                     }
                     break;

                     case MotionEvent.ACTION_MOVE:
                         if (drag && event.getActionIndex() == 0) {
                             // Log.d("detecting","inside the action move");
                             if (touching == false) {
                                 touching = detector.isWaveformAnchor(event.getX(0), event.getY(0));
                             } else if (touching == true) {
                                 float diff = event.getY(0) - loadWaveFormManager.getCh1_pos();
                                 if ((loadWaveFormManager.getCh1_pos() + diff) < (StaticValues.screenHeight - 50)) {
                                     int tempCh1_pos = (int) (loadWaveFormManager.getCh1_pos() + diff);
                                     loadWaveFormManager.setCh1_pos(tempCh1_pos);
                                 }
                                 drawWaveForm.update(loadWaveFormManager);
                             }
                         }
                         break;

                     case MotionEvent.ACTION_UP:
                            // Log.d("detecting","inside the action up");
                            drag = false;
                            touching = false;
                            zoom = false;

                            break;

                     case MotionEvent.ACTION_POINTER_UP:   
                     // here different function                          

             return;        
        }
 });    

Does anyone have any idea about this? Please help me on this one.

Montag451
  • 1,168
  • 3
  • 14
  • 30
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98

2 Answers2

1

It is not clear from your code what is your problem and when does it happen. I don't see any TimerTask or AsyncTask reference.

I guess, you're trying to do some expensive operation in UI thread, and this freezes your application. Possible long-running candidate is drawWaveForm.update(loadWaveFormManager)

If this is so, you should preform your computations asynchronously, and only then update UI.

By the way, your code will not compile at all:

public boolean onTouch(View v, final MotionEvent event)

should return true or false, instead you perform return; at the end of this method. That leads to an assumption, that you're providing irrelevant code in your question, but still want to receive a relevant answer.

Provide relevant code piece for further analyze.

Drew
  • 3,307
  • 22
  • 33
0

Currently you are starting thread on touch event use handler instead of thread

  • Currently I m not seeing any thread but I dont understand what you want ? – Neha - Systematix Mar 29 '14 at 05:21
  • Actually linear layout add to surfaceview. After that using zooming condition to that linear layout first 10 to 20 min it's working fine after that linear layout means activity not responding... – NagarjunaReddy Apr 01 '14 at 03:31