Sunday, March 17, 2013

Android - AlarmManager samples


'Cause of BookmarksOverflow...

First things first - why you should be using an Alarm and not a service

Btw it is impossible to have anything run on install of the app (see comments here) - and LocalBroadcastManager is not applicable here.

Intent resolution

Your first constructor will only work for a BroadcastReceiver registered in the manifest. If you specify a component, Android will attempt to deliver to that component, ignoring your action. 

Cf : Intents can be divided into two groups:

    Explicit intents designate the target component by its name (the component name field, mentioned earlier, has a value set). Since component names would generally not be known to developers of other applications, explicit intents are typically used for application-internal messages — such as an activity starting a subordinate service or launching a sister activity.

    Implicit intents do not name a target (the field for the component name is blank). Implicit intents are often used to activate components in other applications.

Android delivers an explicit intent to an instance of the designated target class. Nothing in the Intent object other than the component name matters for determining which component should get the intent.

Apparently this component must be declared in some manifest :

The name of the component that should handle the intent. This field is a ComponentName object — a combination of the fully qualified class name of the target component (for example "com.example.project.app.FreneticActivity") and the package name set in the manifest file of the application where the component resides (for example, "com.example.project"). The package part of the component name and the package name set in the manifest do not necessarily have to match. 

Flags
Much needed Clarification on the docs for PendingIntent.FLAG_CANCEL_CURRENT
And on FLAG_UPDATE_CURRENT

Last edited : 2013.03.30 14.45 UTC