新活动开始后的Android跟踪触摸事件 [英] Android tracking touch event after new activity starts

查看:23
本文介绍了新活动开始后的Android跟踪触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,一个新活动从触摸按钮(而不是点击)开始,而且我没有抬起手指并希望在新活动之后跟踪触摸的运动.第二个活动中的触摸监听器不响应此动作.我该怎么做?

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?

推荐答案

您可以尝试使用 EventBus 例如(或者您可以使用 Otto 如果你喜欢,由你决定)

You can try to use a EventBus for example (Alternatively you can use Otto if you prefer it, up to you)

注册您的第一个和第二个活动,然后在您的 MotionEvent TOUCH_UP 事件上通知您的订阅者触摸已结束.

Register your first and second activities and then on your MotionEvent TOUCH_UP event notify your subscribers that the touch ended.

eventBus.post(event);

他们将通过 onEvent 方法接收该事件.

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.

这篇关于新活动开始后的Android跟踪触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆