将回调传递给库中的 Activity

Passing Callback to an Activity in a library

我正在使用的库有一个 Android activity。我想将回调传递给 activity 以获得某些用户事件的通知,例如当用户输入特定代码或在屏幕上绘制某些内容时。我找不到将回调传递给 android activity 的方法。

注意: 我可以编辑库,但是,出于体系结构原因和便于测试而不与更大的集成,我更愿意将 activity 保留在库中应用

解决这个问题的最佳方法是什么?有没有 Android 设计模式?

What is the best possible way to solve this?

当这些事情发生时,将 activity 修改为 post 事件总线上的事件(greenrobot 的 EventBus、Square 的 Otto、LocalBroadcastManager。然后,在您的其他地方监听这些事件应用

I prefer to leave the activity within the library for architectural reasons and ease of testing without integrating with the larger app

然后说服库的开发人员将activity修改为post事件总线上的事件(greenrobot的EventBus,Square的Otto,LocalBroadcastManager当这些事情发生时。然后,在您应用的其他地方监听这些事件。

或者,说服开发人员提供一些其他方法来完成此操作(例如,您将 activity 子类化并覆盖某些方法以接收这些事件的通知)。