简体   繁体   中英

Android Alarm Manager Set More One In Same Time Problem

I'm coding a reminder app. When i updated app, i mean changing version infos in gradle file, app abort all reminder alarms. I have method to set again alarms. Already date and time infos exists in sqllite. My method is

void setAlarmsAgain(MyReminder myReminder) {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
            Calendar calendar = Calendar.getInstance();
            Date date;
            date = dateFormat.parse(myReminder.getDate() + " " + myReminder.getTime());

            calendar.setTime(date);
            dayProcess.setReminderAlarm(myReminder.getReminderId(), calendar);
            if (index == reminderStartUps.size()) {
                 handler.removeCallbacks(runnable);
                 sharedPreferences.edit().putString("versionName", appVersionName).apply();
                   //to keep updated version infos and to do control 
            } else {
                 handler.postDelayed(runnable, 1000);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

I have handler,runnable not to block main thread. It's

myReminderList = dayProcess.getRemindersForSetAlarm();
 Collections.sort(myReminderList);
 handler = new Handler();
 runnable = new Runnable() {
 @Override
 public void run() {
     setAlarmsAgain(myReminderList.get(index++));
   }
 };
 handler.post(runnable);

My problem is when i debug the app (Shift-F9) alarms executing correctly, no problem but i run this app (Shift-F10) alarms not ringing. Maybe alarmmanager.set(..) be executed more one in a same time because definetily i have reminders more one, method can't execute correctly so i used handler.postdelayed like methods above. Unfortunately again fail. Alarms not ringing. Can you help me?

I tried only phone running. I mean i didn't use android studio to run my app and it worked. We can understood when we execute app from Android Studio and set alarm manager, it doesn't work correctly. We should use this only with phone. Not editor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM