开发者

need help clearing touch events between activities

开发者 https://www.devze.com 2023-03-14 21:22 出处:网络
Scenario: There are two activitie开发者_Go百科s... Activity A has an imagebutton to launch an intent to show Activity B on screen.

Scenario:

There are two activitie开发者_Go百科s... Activity A has an imagebutton to launch an intent to show Activity B on screen. Activity B has an imagebutton to finish() itself and cause Activity A to be shown. These buttons are at the same location on each activity

Problem:

in Activity B, when I double-tap the button (instead of single tap), Activity A becomes visible but quickly shows Activity B again !

the second touch event seems to carry through to Activity A and it would seem that I could fix this problem by clearing some touch buffer in onCreate() of Activity A.

How can this be done? Or is there another fix ?

I've reproduced this on the emulator (2.2) and on the phone (2.3.3)


I ran into the same issue. Surprisingly, there is very little information about this on the web. My solution combines the comments from this question and onTouchEvent never called MapActivity:

public class MyActivity extends FragmentActivity {

/** Stores the time (as per SystemClock.uptimeMillis()) of the last
* call to onResume() in order to filter out touch events which occurred before
* the activity was visible. */
private long resumeTime = 0;

@Override
public void onResume() {
    super.onResume();

    resumeTime = SystemClock.uptimeMillis();
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (event.getEventTime() < resumeTime) {
    Log.v(TAG, "Discarded touch event with time earlier than onResume()");
    return true;
    }

    return super.dispatchTouchEvent(event);
}
}


Double tap isn't really a common android event. It sounds like your click is not coming through one activity to another (which I think is impossible) but that you are clicking once on B and once on A.

What you could do is in onActivityResult() capture the time, and don't like people click the imagebutton for like 0.3seconds or something after the activity result.

0

精彩评论

暂无评论...
验证码 换一张
取 消