Search code examples
androidalarmmanager

Check If alarmManager has already been running


I have read this question : How to check if AlarmManager already has an alarm set?

And the Chris Knight answer is the most correct answer maybe. But i didn't understand in boolean line :

boolean alarmUp = (PendingIntent.getBroadcast(context, 0, 
        new Intent("com.my.package.MY_UNIQUE_ACTION"),   <--------?
        PendingIntent.FLAG_NO_CREATE) != null);

Where is "com.my.package.MY_UNIQUE_ACTION" coming from ?

Is it from manifest or what ?

I'm sorry for duplicating.


Solution

  • boolean alarmUp = (PendingIntent.getBroadcast(context, 0, 
            new Intent("com.my.package.MY_UNIQUE_ACTION"),
            PendingIntent.FLAG_NO_CREATE) != null);
    

    In the above statememnt "com.mypackage" is package name where as "MY_UNIQUE_ACTION" is class name where you handle AlarmManager.

    The key here is the FLAG_NO_CREATE which as described in the javadoc: if the described PendingIntent does not already exists, then simply return null (instead of creating a new one)

    so from the above statement you can know that the boolean value returns true if AlarmManager class is running else false.

    You can get package name by various method

    1. Simply by typing the package name.
    2. As described in this link