我很少遇到手机进入状态(称为“有趣状态”)的问题,我的意图服务不会从广播接收器获取startService命令。 (是的,清单中定义了接收者和服务)。
在这个例子中,我正在侦听推送通知,然后调用CheckinService。 接收器:
public class PushReceiver extends BroadcastReceiver {
private static final String LOG_TAG = "push_receiver";
@Override
public void onReceive(Context context, Intent intent) {
logger.putExtra("debug", "Received Push");
Intent serviceIntent = new Intent(context, CheckinService.class);
context.startService(serviceIntent);
logger.putExtra("debug", "Sent to Service");
}
服务:
public class CheckinService extends IntentService {
private static final String LOG_TAG = "checkin_service";
public static final int SERVICE_ID = 3;
public CheckinService() {
super(LOG_TAG);
Log.i(LOG_TAG, "Service says: Checkin service started no constructor");
}
public CheckinService(String name) {
super(LOG_TAG);
Log.i(LOG_TAG, "Service says: Checkin service started with constructor");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.i(LOG_TAG, "Auto Checkin started");
.....tons of genius logic.....
}
}
因此,当手机处于有趣的状态时,“收到的推送”会被记录,“发送到服务”会被记录,但服务的构造函数和onHandleIntent方法永远不会被调用。
我也有这种情况不仅发生在推动上,而且发生在不精确的重复警报和其他人的接收器上,但这两个已经得到确认。
同样,这是非常非常罕见的,似乎是在手机闲置一段时间之后发生的;并且可能进入省电模式。
此外,终止应用程序的过程会清除它。
答案 0 :(得分:1)
我意识到这里发生了什么。
IntentService是单线程的。因此,如果我的“..... ton of genius logic .....”中的某些东西被阻塞(就像没有超时的http请求那样),那么进入该服务的下一个意图就不会被处理。
很好,也很谦卑。