Vincent Hiribarren
Vincent Hiribarren

Reputation: 5294

Equivalent of LocalBroadcastManager without Android support library

There are lots of examples on StackOverflow and elsewhere that use the class LocalBroadcastManager to avoid broadcasting events outside of an app.

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 the standard SDK that does not use the Android support library?

It does not seem that the sendBroadcast method in android.content.Context has this kind of security granularity.

Upvotes: 9

Views: 1025

Answers (1)

Sulfkain
Sulfkain

Reputation: 5119

No it doesn't exist, If you want to recreate this class you can read the source code to implement yourself without using the support lib. Anyway, what's the problem using the support lib? it's lightweight.

A bit workaround could be using the normal BroadCastReceiver and put <android:exported="false"> on your manifest, inside this receiver, this avoid to other apps send you intents, so you are faking a local receiver.

Note: I said faking, because the LocalBroadcastManager has optimizations, by not spread the intent to the system...

Hope this helps.

Upvotes: 3

Related Questions