Android AlarmManager stops when activity die

前端 未结 9 2143
鱼传尺愫
鱼传尺愫 2020-12-29 07:00

I start AlarmManager with PendingIntent and on few phones Alarm is not responding. On some devices is working ok on others it fails. I have made a few tests on different pho

9条回答
  •  青春惊慌失措
    2020-12-29 07:26

    Try this it works when activity is not running..
    
            Calendar calendar = Calendar.getInstance();
    
            long timemills = calendar.getTimeInMillis();
            Intent myIntent = new Intent(this, TimeChangeReceiver.class);
            pendingIntent = PendingIntent.getBroadcast(this, 0, myIntent, 0);
    
            AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    
                alarmManager.set(AlarmManager.RTC, timemills, pendingIntent);
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timemills,
                        10000, pendingIntent);
    

提交回复
热议问题