setiting repeated task in AlarmManager problem
I trying to set a repeating task using the AlarmManager
the task is to send a broadcast to my BroadcastReciever that runs a service (if it isn't already).
this is the code which sets the repeating task:
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 10000 , 60 * 1000 , pendingIntent);
now the repeating task works fine, but if my application is still running, and I stop it, I don't get the broadcast anymore.
what am I doing wrong here?
edit:
the manifest: (only the relevant part)
<service android:name=".TQService"/>
<receiver android:name=".TQServiceManager"
android:process=":remote">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="com.xxxxx.tq.TQServiceManager"></action>
</intent-filter>
</receiver>
the code:
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent("com.xxxxx.tq.TQServiceManager"), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemCl开发者_运维问答ock.elapsedRealtime() + 1000 , 30 * 1000 , pendingIntent);
How is your BroadcastReceiver registered? It must be in your AndroidManifest.xml file, and not manually registered. The fact that it works when your app is running and doesn't when your app is not running sounds like it isn't in the manifest.
精彩评论