Question

i am android developer i want to declare my broadcast receiver in manifest file but problem is " i am call Receiver by anonymous class " so this class donot have name then how can i declare without name class in manifest file..

Was it helpful?

Solution

For broadcast receivers that you can't declare via codes then you need to declare it in manifest and you have to provide a concrete class for your receiver.

But for those receivers that can be registered via codes, you can use anonymous class instance of BroadcastReceiver.

--EDIT---

MyReceiver.java

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) { 
    }
} 

AndroidManifest

 <application>

     <!-- some other codes here -->

     <receiver android:name="MyReceiver" >
        <intent-filter>
            <!-- Sample filter to listen when device boot is completed -->
            <!-- This type of receiver cant be declared in codes -->
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
     </receiver>

 </application>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top