Leonard Febrianto
Leonard Febrianto

Reputation: 984

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.

Upvotes: 2

Views: 3629

Answers (2)

Sagar Limbani
Sagar Limbani

Reputation: 105

Intent intent = new Intent("com.my.package.MY_UNIQUE_ACTION");
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, 
                                      intent, PendingIntent.FLAG_UPDATE_CURRENT);

Upvotes: -1

c__c
c__c

Reputation: 1612

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

Upvotes: 3

Related Questions