Equivalent to LocalBroadcastManager without Android library support

There are many examples in StackOverflow and elsewhere that use the LocalBroadcastManager class to avoid broadcast events outside the application.

However, this class uses the Android support library, as shown in the package name: android.support.v4.content.LocalBroadcastManager .

Is there an equivalent of LocalBroadcastManager in a standard SDK that does not use the Android support library?

It doesn't seem like the sendBroadcast method in android.content.Context has this degree of security granularity.

+8
android sdk android-broadcast
source share
1 answer

No, this does not exist. If you want to recreate this class, you can read the source code for the implementation yourself without using lib. Anyway, what's the problem with using lib support? it is light weight.

A small workaround is to use the usual BroadCastReceiver and put <android:exported="false"> in your manifest inside this receiver, this avoids sending other applications you intend to, so you pretend to be a local receiver.

Note. I said it was a fake, because LocalBroadcastManager has optimization without spreading intentions on the system ...

Hope this helps.

+2
source share

All Articles