In my application, a new activity starts on touching a button (not click) and further I don't lift the finger and wish to track the motion of touch after that in new activity. The on touch listener in second activity does not respond to this motion. How can I do this?
Asked
Active
Viewed 878 times
3
-
Same problem, the old activity seems to keep receiving them and until you don't move_up and then touch again the screen, the new activity doesn't respond... struggling with that as well. What I am basically trying is move_down touching a view, then I start a new activity which will have a copy of this view on the same same position (I pass the info of the position of the view in the old activity to the new activity) then I drag the new view in the new activity without moving up my finger. – jpardogo Feb 11 '15 at 17:30
-
it would be easier if you use a single activity and replace fragments, because you can intercept touch events at activity level – sockeqwe Feb 11 '15 at 19:54
-
The problem in my case is that is not just 1 activity that starts this kind of overlay for dragging elements around. You can drag this element on any activity of the app at any point in the app, so it wouldn't make sense create fragment containers in all activities for the possible situation, I do need a new activity. Cleaner, more efficient, less code. – jpardogo Feb 12 '15 at 10:20
-
2The best solution so far is the EventBus, although I was playing with MotionEvent.obtain to fake events...didn't work anything yet, if it does, I will write back. I would like to point as well to the answer of the android expert David Smith when I asked him on Google+ . Answer: https://plus.google.com/u/0/110611379037323129529/posts/Mpp1KDqN1cQ – jpardogo Feb 12 '15 at 10:22
1 Answers
1
You can try to use a EventBus for example (Alternatively you can use Otto if you prefer it, up to you)
Register your first and second activities and then on your MotionEvent TOUCH_UP event notify your subscribers that the touch ended.
eventBus.post(event);
They will receive that event on the onEvent method.
public void onEvent(AnyEventType event) {/* Do something */};
I think that it´s not posible to share events trough activities natively, but you can try this way.

reixa
- 6,903
- 6
- 49
- 68
-
That's not really a solution to manage the different motion events you can receive. Also because Its a new activity it means it can be trigger from anywhere. I have the same problem. It am trying to find out how the new activity can start intercepting the events from the moment it lunch. – jpardogo Feb 11 '15 at 17:20