public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); Log.d("Restart","First"); Intent toRun = new Intent(this,AlarmRestart.class); PendingIntent pendingToRun = PendingIntent.getbroadcast(this,toRun,0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.cancel(pendingToRun); am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,System.currentTimeMillis(),10000L,pendingToRun); Log.d("Restart","Second");}
这是在另一个文件中:
public class AlarmRestart extends broadcastReceiver { public voID onReceive(Context context,Intent intent) { Log.d("Restart","Third"); }}
这就是“adb shell dumpsys alarm”所说的
com.packagename.restart5715ms running,64 wakeups3 alarms: flg=0x14 cmp=com.packagename.restart/.AlarmRestart61 alarms: flg=0x14 cmp=com.packagename.restart/.recIEver.AlarmRestart解决方法 AlarmRestart是一个broadcastReceiver.它不是服务.然而,您正在尝试使用getService()PendingIntent.那样不行.将getService()更改为getbroadcast(),你应该有更好的运气. 总结
以上是内存溢出为你收集整理的Android SetInexactRepeating根本没有触发全部内容,希望文章能够帮你解决Android SetInexactRepeating根本没有触发所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)