Skip to content Skip to sidebar Skip to footer

What Is The Right Way Of Static Registration Of Custom Broadcast Receiver In Android?

Instead of dynamic registration, I want to statically register my receiver. For dynamic registration, it works well, I was using this : .. static private IntentFilter GPSActionFil

Solution 1:

When declaring an intent-filter action in the manifest, the android:name must be a string literal and can not access Strings from classes. Also, I recommend you prepend your fully qualified package name to the intent action ie:

public static final String GPS_SERVICE = "com.example.LocationListener.ACTION_GPS_SERVICE"

Then change

<action android:name="LocationListener.GPS_SERVICE" />

To

<action android:name="com.example.LocationListener.ACTION_GPS_SERVICE" />

Solution 2:

First, you cannot have a private BroadcastReceiver in the manifest, as Android needs to be able to create an instance of it. Please make this public.

Second, the syntax for the name of static inner classes is LocationListener$GPSActionReceiver, not LocationListener.GPSActionReceiver.


Post a Comment for "What Is The Right Way Of Static Registration Of Custom Broadcast Receiver In Android?"