2013-07-24 2 views
0

나는 경보의 명부가있다, 나는 첫번째를두고 경보를 울릴 때 다음을 둔다. 이것은 작동한다. 그러나 응용 프로그램이 백그라운드에서 충분한 시간 동안 작동하지 않으면 알람이 작동하지 않습니다.배경에있는 AlarmManager

<receiver android:name=".Alertas_Broadcast" > 
     <intent-filter> 
      <action android:name="com.pack.pack.Alertas" /> 

      <category android:name="com.pack.pack" /> 
     </intent-filter> 
    </receiver> 

그리고 방송과 새로운 알람 넣어 기능 :

public class Alertas_Broadcast extends BroadcastReceiver { 
@Override 
public void onReceive(Context context, Intent intent) { 
    Bundle extras = intent.getExtras(); 

    String mensaje = ""; 
    if (extras != null) 
     mensaje = extras.getString("mensaje"); 

    if (!mensaje.equals("")){ 
     Utilidades.generateNotification(context, mensaje, Main.class, null); 
     // I put the next alarm calling setNextAlarm with the new parameters 
    } 
} 
} 

public void setNextAlarm (long milisegundos, String mensaje){ 
    Bundle extras = new Bundle(); 
    extras.putString("mensaje", mensaje); 
    Intent i = new Intent("com.pack.pack.Alertas"); 
    i.putExtras(extras); 

    PendingIntent pintent = PendingIntent.getBroadcast(InfoApp.miContexto, (int) milisegundos, i, PendingIntent.FLAG_UPDATE_CURRENT); 
    AlarmManager alarm = (AlarmManager)InfoApp.miContexto.getSystemService(Context.ALARM_SERVICE); 

    if (milisegundos != 0){ 
     alarm.setRepeating(AlarmManager.RTC_WAKEUP, milisegundos, 99999999, pintent); 
    } 
    else{ 
     alarm.cancel(pintent); 
    } 
} 

문제가를

나는 매니페스트에 넣어? 문제는 수신자의 행동이라고 생각하지만 어떻게 해결해야할지 모르겠다. 많은 리소스를 소비하기 때문에 항상 듣는 것이 좋지 않습니다.

죄송합니다. 내 영어로 죄송합니다. 감사합니다.

답변

0

활동이 백그라운드에서 충분히 길면 시스템에 의해 종료되었을 수 있습니다. 목표를 달성하기 위해 서비스와 setForeground()를 사용해 볼 수 있습니다.

0

어떻게 다음 알람을 설정하고 있습니까? 당신이 서비스를 통해 그것을하는 경우에, 당신은 wakelock를 취득 할 필요가있다.

휴대 전화가 절전 상태이고 경보를 수신하면 BroadcastReceiver가 onReceive() 메소드에있는 동안 잠에서 깨어나고 잠자기 상태가됩니다. 따라서 "setNextAlarm"이 호출된다는 보장은 없습니다.

+0

데이터베이스의 다음 날짜를 검색하고 새 매개 변수로 setNextAlarm을 호출합니다. 매니페스트에 WAKE_LOCK 권한이 있지만 서비스가 없습니다. – user1852854