0

Apparently, the AlarmManager is the cause for the application to crash. When excetuting the method setExactAndAllowWhileIdle the app stops working.

I'm working on an app to collect location of users and I'm using the AlarmManager to schedule when to collect the location to send through REST. It works fine in previous Android versions, but when tested on Android 8 (on an LG K12 to be more specific) it had this crashing problem. I tried putting "try-catches" throughout the code but none of them triggered.

The app itself checks constantly if the user is moving, and only if it moves a certain distance it sends the location. I've noticed that if I don't move, the app doesn't crash.

public static void startInMiliSeconds(Context ctx, String action, AlarmManager manager, long timeInMiliseconds) {
   Intent intent = new Intent(action);
   PendingIntent pending = PendingIntent.getBroadcast(ctx, 0, intent, 0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        manager.setExactAndAllowWhileIdle(AlarmManager.RTC, timeInMiliseconds, pending);
    } else {    
        manager.setExact(AlarmManager.RTC, timeInMiliseconds, pending);
    }
}

The app itself is sending the current location at the moment you log in and synchronize, but if the telephone moves just a little bit from location, the app crashes.

StackTrace

hanielhgc
  • 1
  • 1

0 Answers0