Receiver class is anonymous so how can i declare receiver in manifest file in android

StackOverflow https://stackoverflow.com/questions/22706260

  •  23-06-2023
  •  | 
  •  

سؤال

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..

هل كانت مفيدة؟

المحلول

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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top