简体   繁体   中英

Broadcast is not getting received[LocalBroadcastManager] Android

Can you help me resolve this issue, I have implemented a receiver(registered via XML) which listens for particular local broadcasts, and in turn starts a service for further processing, but somehow that receiver is not receiving any broadcasts.

Although another receiver, which is registered locally through code is able to receive the broadcast, can you help me fix this. Below is my code.

// Sending broadcast
Intent intent = new Intent(Constants.ACTION_PROFILE_UPDATED);
LocalBroadcastManager.getInstance(POC.getAppContext()).sendBroadcast(intent);

// Receiver
public class LocalReceiver extends BroadcastReceiver {

    private final String TAG = LocalReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "received"); // its not received
        if(intent.getAction() != null){
            String action = intent.getAction();
            Log.i(TAG, "action = " + action);

            if(action.equals(Constants.ACTION_PROFILE_UPDATED)){


// IN manifest
        <receiver
            android:name=".LocalReceiver"
            android:enabled="true"
            android:exported="false" >
            <intent-filter>
                <action android:name="local.action.profile.updated" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

This damn code is not working, no where in developer guide it says local broadcast wont be received, through receiver registered through xml.

Please help, Thanks.

I have implemented a receiver(registered via XML) which listens for particular local broadcasts

That is not possible. LocalBroadcastManager does not work with manifest-registered receivers, only with receivers registered via registerReceiver() , called on the LocalBroadcastManager instance itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM