alarmmanager

Android: how to schedule an alarmmanager broadcast event that will be called even if my application is closed?

烈酒焚心 提交于 2019-12-18 07:07:03
问题 My app needs to execute a specific task every hour. It does not matter if app is runing, suspended, or even closed. When app is running or suspended, I can do it by just scheduling an AlarmManager broadcastreceiver. But when the application is closed, I have to call "unregisterReceiver" to not leak an intent, and app will never be wake up (or something) to process the task. Then, the question is: how to schedule an alarmmanager task that I don't need to unregister, so it will be called even

Weird AlarmManager behaviour

我的梦境 提交于 2019-12-18 07:02:36
问题 I have 2 BroadcastReceivers and 2 intents, I want to click a button, 5m later start broadcast1 and 10m later start broadcast2, what's happening is they both start 10m after I click, My guess is, the intents are not unique, but I'm setting a diffrent reqeustCode for each of them. Button's OnClick: Bundle bd = new Bundle(); bd.putInt("mInt", i); Intent intent1 = new Intent(getActivity(), Broadcast_1.class); intent1.putExtras(bd); PendingIntent pendingIntent1 = PendingIntent.getBroadcast

Weird AlarmManager behaviour

白昼怎懂夜的黑 提交于 2019-12-18 07:02:24
问题 I have 2 BroadcastReceivers and 2 intents, I want to click a button, 5m later start broadcast1 and 10m later start broadcast2, what's happening is they both start 10m after I click, My guess is, the intents are not unique, but I'm setting a diffrent reqeustCode for each of them. Button's OnClick: Bundle bd = new Bundle(); bd.putInt("mInt", i); Intent intent1 = new Intent(getActivity(), Broadcast_1.class); intent1.putExtras(bd); PendingIntent pendingIntent1 = PendingIntent.getBroadcast

How to set an exact repeating alarm on API 19 (kitkat)?

老子叫甜甜 提交于 2019-12-18 05:48:05
问题 Starting from API 19, setRepeating() works the same way as setInexactRepeating() . What's the new way of setting an exact repeating alarm? I.e. What's the API 19 version of the good old setRepeating() ? Could you please provide an example for setting an alarm at 7:30 every morning (repeating daily) on KitKat? 回答1: It doesn't exist, unfortunately. From the documentation: Note: as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one

cancel repeating alarm at specific time

允我心安 提交于 2019-12-18 05:15:12
问题 I'm looking to cancel 2 repeating alarms at a specific time but the app currently decides to call the cancel as soon as you create the alarms. For example if you set the the time to end repeation at 13:18 then the repeating alarm should repeat until it is that time. Here is some of the code I have been toying with: Toast.makeText(this, "Alarm Scheduled for " + midnight, Toast.LENGTH_LONG).show(); AlarmManager Databackon = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Databackon.set

How to use alarmmanager 2 times every day?

£可爱£侵袭症+ 提交于 2019-12-18 05:06:23
问题 I have used the following code to set alarmmanager for only one time every days, I'd like to have 2 different time to set, so 2 times every days. My code: Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 10); calendar.set(Calendar.MINUTE, 35); calendar.set(Calendar.SECOND, 0); AlarmManager am = (AlarmManager) getApplicationContext().getSystemService (Context.ALARM_SERVICE); PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent

FLAG_CANCEL_CURRENT or FLAG_UPDATE_CURRENT

笑着哭i 提交于 2019-12-18 04:03:23
问题 My app sets a repeating alarm on user interaction, it might change the interval time set for the broadcast with Alarm Manager. There is not much in the way of extras. Is the update or cancel flag better in this case? Thanks 回答1: If you are not using extras, you don't have to specify any of those flags. They only change how the systems handles extras with a PendingIntent : replace the ones in the current matching (cached by the system PendingIntent ) or cancel it and create a new one. Refer to

Android alarm not working

岁酱吖の 提交于 2019-12-18 04:03:09
问题 I've been struggling with this for hours. I've also checked the documentation and several topics. I found this code in two topics, both guys said the code was working perfectly, but not on my computer. The first Toast appears, but the second one never. What is wrong? public class HelloAndroid2 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = new Intent(this, AlarmReceiver.class);

Android alarm not working

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 04:03:06
问题 I've been struggling with this for hours. I've also checked the documentation and several topics. I found this code in two topics, both guys said the code was working perfectly, but not on my computer. The first Toast appears, but the second one never. What is wrong? public class HelloAndroid2 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = new Intent(this, AlarmReceiver.class);

Android - How to set a notification to a specific date in the future?

青春壹個敷衍的年華 提交于 2019-12-18 03:33:24
问题 Edit: SOLVED! Ever wanted to set a notification from a specific date starting a certain point in time (when an activity is started or when a button is pressed?) Read more to find out how: //Set a notification in 7 days Calendar sevendayalarm = Calendar.getInstance(); sevendayalarm.add(Calendar.DATE, 7); Intent intent = new Intent(this, Receiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 001, intent, 0); AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE