【发布时间】:2017-03-09 02:46:32
【问题描述】:
我正在尝试使用事件总线将事件从我的库通知到服务。 到目前为止,我一直在使用这样的 EventBus:
public abstract class MLibraryClass{
....
EventBus.getDefault().post(event);
...
}
public class MService{
...
public void onEvent(Event event){
//do stuff
}
}
现在我创建了一个接口来使用回调。问题是回调有一个空引用,我不知道如何实例化它。
界面:
public Interface MInterface{
void doStuff(Event event);
}
库类:
public abstract class MLibraryClass{
...
MInterface interface;
Event event;
...
public void onEvent(){
interface.doStuff(event)
}
...
}
服务:
public class MService implements MInterface{
...
void doStuff(Event event){
//some code
}
...
}
【问题讨论】:
标签: android service interface callback