如果应用程序被终止,AlarmManager 将不再启动我的后台服务(任务管理器 - 退出应用程序)
朋友们,
我有一个设置 AlarmManager 的活动。警报管理器应在特定时间段内调用后台服务。一切都很完美,直到我使用 Android 任务管理器终止应用程序 - 退出应用程序。然后就什么都没有发生了。 有什么办法可以避免丢失警报吗?
这是我设置警报的活动
PendingIntent pi;
AlarmManager mgr;
mgr=(AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(DataCollectionActivity.this, HUJIDataCollectionService.class);
pi = PendingIntent.getService(DataCollectionActivity.this, 0, i, 0);
mgr.cancel(pi);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() , 1* 60* 1000, pi);
该服务只是一个常规活动扩展服务,
这里是我的清单文件
<service android:name=".services.HUJIDataCollectionService" android:process=":remote"/>
<activity android:name=".activities.DataCollectionActivity"
android:label="@string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.sheep.activities.DataCollectionActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
感谢您的帮助!
Friends,
i have an Activity that sets up an AlarmManager. The Alarmmanager should call a backgroundservice in a certain timeperiod. Everything works perfect untill i kill the application with the Android Taskmanager - exit application. Then nothing happens anymore.
Is there any way to avoid loosing the Alarms???
Heres my Activity to set up the Alarm
PendingIntent pi;
AlarmManager mgr;
mgr=(AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(DataCollectionActivity.this, HUJIDataCollectionService.class);
pi = PendingIntent.getService(DataCollectionActivity.this, 0, i, 0);
mgr.cancel(pi);
mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() , 1* 60* 1000, pi);
The service is just a regular Activity extends Service,
and here my manifest file
<service android:name=".services.HUJIDataCollectionService" android:process=":remote"/>
<activity android:name=".activities.DataCollectionActivity"
android:label="@string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.sheep.activities.DataCollectionActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
appreciate your help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这肯定会发生在 Android 2.1 及更早版本上。相关效果(阻止接收广播)会影响 Android 3.1+。
不要使用任务杀手或从“设置”中强行停止来终止应用程序。
This definitely happens on Android 2.1 and earlier. A related effect (preventing broadcasts from being received) affects Android 3.1+.
Don't kill the application with a task killer or force-stop from within Settings.