请教一个关于DSP 关于manager的作文问题

请教大家一个关于DSP时钟的问题_百度知道系统辅助类排行
喜欢这个应用的还喜欢DSP一些常见问题(1)_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
DSP一些常见问题(1)
上传于||暂无简介
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩4页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢请教一个关于android AlarmManager的一个问题
- 开源中国社区
当前访客身份:游客 [
当前位置:
不是说可用AlarmManager实现全局定时,不依赖于应用程序的么?为什么我写了一个简单的定时任务,当程序被关闭后,时间到时并不能实行定时的任务,只有程序开着才行?求解,谢谢!
共有12个答案
<span class="a_vote_num" id="a_vote_num_
根据API描述,AlarmManager就是为定时发送Intent而生,但也有一些注意事项,是不是阁下的使用有问题,可否贴出代码?
Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running.
Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.
If your alarm receiver called
, it is possible that the phone will sleep before the requested service is launched. To prevent this, your BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone continues running until the service becomes available.
for more info: /reference/android/app/AlarmManager.html
<span class="a_vote_num" id="a_vote_num_
引用来自“红猎人”的答案根据API描述,AlarmManager就是为定时发送Intent而生,但也有一些注意事项,是不是阁下的使用有问题,可否贴出代码?
Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running.
Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.
If your alarm receiver called
, it is possible that the phone will sleep before the requested service is launched. To prevent this, your BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone continues running until the service becomes available.
for more info: /reference/android/app/AlarmManager.html
感谢您的回答,代码如下:
*************** &
& & & & & & & & AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
PendingIntent operation = getPendingIntent(context);
am.setRepeating(AlarmManager.RTC_WAKEUP, getTriggerAtTime(),
24 * 60 * 1000, operation);
***************
public PendingIntent getPendingIntent(Context context)
Intent intent = new Intent(context, MeiOffReceiver.class);
intent.setAction(MUtil.ACTION_TIME_OUT);
PendingIntent pi = PendingIntent.getBroadcast(context, _id, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
*****************
主要是我程序中,程序被360优化大师的一键清理杀死后,我的广播接收器就收不到广播了。也试过用其他一些内存释放程序杀后,倒是还能用。360那个就不行 了,360太狠了。这种情况下该怎么做才能让360杀后还能用,就想系统自带的闹钟一样?希望您 能教我,非常感谢!
<span class="a_vote_num" id="a_vote_num_
你的广播接收器是通过代码动态注册还是在AndroidManifest.xml中声明的?如果是前者,程序被杀死后是无法收到广播的,改为后者试试?
<span class="a_vote_num" id="a_vote_num_
引用来自“红猎人”的答案你的广播接收器是通过代码动态注册还是在AndroidManifest.xml中声明的?如果是前者,程序被杀死后是无法收到广播的,改为后者试试?是在
AndroidManifest.xml中静态注册的。
<span class="a_vote_num" id="a_vote_num_
是这样啊,那就需要调试一下了,请用adb logcat 进一步确认一下:这个Intent到时间了之后是否发出。如果没有发则可确定是AlarmManager的问题,否则可能是你的APP的问题。
如果可以的话,请附上AndroidManifest.xml和调试信息。
<span class="a_vote_num" id="a_vote_num_
引用来自“红猎人”的答案
是这样啊,那就需要调试一下了,请用adb logcat 进一步确认一下:这个Intent到时间了之后是否发出。如果没有发则可确定是AlarmManager的问题,否则可能是你的APP的问题。
如果可以的话,请附上AndroidManifest.xml和调试信息。
AndroidManifest.xml:
&manifest xmlns:android=&/apk/res/android&
package=&com.yehe.mei.off&
android:versionCode=&1&
android:versionName=&1.0& &
android:minSdkVersion=&15&
android:targetSdkVersion=&15& /&
&uses-permission android:name=&android.permission.RECEIVE_BOOT_COMPLETED& /&
&uses-permission android:name=&android.permission.WRITE_SETTINGS& /&
&uses-permission android:name=&android.permission.WAKE_LOCK& /&
&uses-permission android:name=&android.permission.READ_PHONE_STATE& /&
&uses-permission android:name=&android.permission.DEVICE_POWER& /&
&uses-permission android:name=&android.permission.ACCESS_WIFI_STATE& /&
&uses-permission android:name=&android.permission.CHANGE_WIFI_STATE& /&
&application
android:icon=&@drawable/ic_launcher&
android:label=&@string/app_name&
android:theme=&@android :style/Theme.DeviceDefault.Light& &
android:name=&.MainActivity&
android:excludeFromRecents=&true&
android:label=&@string/title_activity_main& &
&intent-filter&
&action android:name=&android.intent.action.MAIN& /&
&category android:name=&android.intent.category.LAUNCHER& /&
&/intent-filter&
&/activity&
android:name=&.ActionListActivity&
android:label=&@string/title_activity_new_add& &
&/activity&
android:name=&.TaskSettingActivity&
android:label=&@string/title_activity_new_add& &
&/activity&
android:name=&.WeekActivity&
android:label=&@string/title_activity_new_add& &
&/activity&
android:name=&.MeiOffService&
android:exported=&false& &
&intent-filter&
&action android:name=&com.yehe.mei.off.action.TIME_OUT& /&
&/intent-filter&
&/service&
android:name=&.MeiOffReceiver&
android:exported=&false& &
&intent-filter&
&action android:name=&com.yehe.mei.off.action.TIME_OUT& /&
&/intent-filter&
&/receiver&
&receiver android:name=&.InitReceiver& &
&intent-filter&
&action android:name=&android.intent.action.BOOT_COMPLETED& /&
&/intent-filter&
&/receiver&
&/application&
&/manifest&
其中MeiOffReceiver是接收时间到后AlarmManager发送来的广播。
由于在adb logcat中AlarmManager发送广播时并没有提示什么信息,因此我另写了两个程序,假设上面的程序为A,另写的两个分别为B和C。A为定时发送广播和接收广播,B为手动发送广播,C为接收广播。其中Intent的Action都为&com.yehe.mei.off.action.TIME_OUT&,C的广播接收器注册与MeiOffReceiver一样,但android:exported=&true& 。
1、当A和C同时运行时,A定时发送的广播,A与C都能接收到;当用360杀死C后,A能接收到A定时发送的广播,而C接收不到。
2、当A和C同时运行时,A设定好定时发送广播后,用360将A杀死,C继续运行,时间到后C并没有接收到AlarmManager发送过来的A设定的Intent。
3、杀死A,当B和C同时运行时,通过B手动发送广播,C能接收到B发送过来的广播;当用360杀死C后,通过B手动发送广播,C便不能接收到B发送过来的广播了。
综上述,足以证明360在杀死程序后,程序中的广播接收器和通过AlarmManager设置的定时发送Intent功能都全部失效!
唉!头都大了!可是为什么系统自带的闹钟,用360怎么杀闹钟都能准时闹呢?费解!
<span class="a_vote_num" id="a_vote_num_
你可以把系统闹钟的代码拿来参考一下
<span class="a_vote_num" id="a_vote_num_
引用来自“wisely”的答案你可以把系统闹钟的代码拿来参考一下
谢谢您提供了源码,但也是一样的,被杀后也是不会闹。不过我再现也不再纠结这个了,我就给它一直挂着了。
--- 共有 1 条评论 ---
请问您最后是怎么解决的呢?现在遇到相同的问题了!
(4年前)&nbsp&
<span class="a_vote_num" id="a_vote_num_
我也遇到该问题,请问下楼主有解决么?
<span class="a_vote_num" id="a_vote_num_
更多开发者职位上
有什么技术问题吗?
丶一意孤行的其它问题
类似的话题

我要回帖

更多关于 dsp manager 的文章

 

随机推荐