我有一个问题,我创建了一个应该在 AlarmManager 唤醒时创建的服务。实际上它正在开始( onStartCommand被调用,我看到了 toast),但在日志中同时出现:
09-19 02:48:32.537: I/ActivityManager(1983): START {flg=0x4 cmp=com.my.app/.syncService.SyncService (has extras)} from pid -1
09-19 02:48:39.662: W/ActivityManager(1983): Unable to start service Intent { act=com.my.app.syncService.SyncService flg=0x4 (has extras) }: not found
意图:
Intent intent = new Intent("com.my.app.syncService.SyncService");
PendingIntent pendingIntent = PendingIntent.getService(this, 12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000*30, pendingIntent);
我的服务看起来像这样:
public class SyncService extends Service{
@Override
public void onCreate() {
Log.d("SyncService", "onCreate");
Log.d("SyncService", "onCreate");
Log.d("SyncService", "onCreate");
super.onCreate();
Toast.makeText(this, "Debug: SyncService created", Toast.LENGTH_LONG).show();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Debug: SyncService onStartCommand", Toast.LENGTH_LONG).show();
return super.onStartCommand(intent, flags, startId);
}
}
安卓清单:
<application>
...
<service android:enabled="true" android:name="com.my.app.syncService.SyncService"/>
</application>
是不是有点奇怪?onCreate get 只调用一次,这对我来说很有意义,但其余的呢?