我正在尝试实现一个功能,当用户关闭应用程序(刷掉)时,该功能将进行一些清理。
内部活动。班
@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void stopSearching(MyService.StopSearching stopSearching)
{
Log.d(TAG, "stopSearching: ");
}
我的服务。班
public class MyService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("ClearFromRecentService", "Service Started");
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("ClearFromRecentService", "Service Destroyed");
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Log.e("ClearFromRecentService", "END");
EventBus.getDefault().post(new StopSearching());
stopSelf();
}
public class StopSearching {
StopSearching() {
}
}
}
但我得到:
EventBus:没有为事件类注册订阅者
通用域名格式。talkie公司。阿沙宁。firebaseapp。另外MyService$停止搜索
EventBus:没有为事件类注册订阅者
组织。绿色机器人。事件总线。无订阅事件