AlarmManager长时间不工作

时间:2016-06-15 14:41:00

标签: android alarmmanager alarm

我的代码使用AlarmManager类设置闹钟,它会触发广播接收器发送短信。 如果我长时间设置闹钟,闹钟就不起作用,因为应用程序被杀了。

         Calendar c=Calendar.getInstance();
         Long a ;
         if(cal.get(Calendar.HOUR_OF_DAY)<c.get(Calendar.HOUR_OF_DAY))
             h=(cal.get(Calendar.HOUR_OF_DAY)+24-c.get(Calendar.HOUR_OF_DAY))*60;
         else
            h=(cal.get(Calendar.HOUR_OF_DAY)-c.get(Calendar.HOUR_OF_DAY))*60;
         m=(cal.get(Calendar.MINUTE)-c.get(Calendar.MINUTE));
         a=(m+h)*60;
         myIntent = new Intent(this, MyReceiver.class);
         myIntent.putExtra("pos",array.select);


         //Pending Intent for sending the intent afterwards
         pendingIntent[array.select] = PendingIntent.getBroadcast(this.getApplicationContext(), array.select, myIntent, 0);
         alarmManager[array.select] = (AlarmManager) (this.getSystemService(Context.ALARM_SERVICE));
         alarmManager[array.select].set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime()+a*1000, pendingIntent[array.select]);

         pendingarray.add(pendingIntent[array.select]);

0 个答案:

没有答案