In my app,i want to use Shared Preferences inside a broadcast receiver...But i cant access the getPreferences() method inside...
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
I cant call with the context object...any other method???
Retrieve the current result extra data, as set by the previous receiver. This can be called by an application in onReceive(Context, Intent) to allow it to keep the broadcast active after returning from that function.
A broadcast receiver will always get notified of a broadcast, regardless of the status of your application. It doesn't matter if your application is currently running, in the background or not running at all.
Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.
Android BroadcastReceiver is a dormant component of android that listens to system-wide broadcast events or intents. When any of these events occur it brings the application into action by either creating a status bar notification or performing a task.
You can use Context from onReceive(Context arg0, Intent arg1)
of BroadReceiver.
@Override public void onReceive(Context arg0, Intent arg1) { SharedPreferences prefs = arg0.getSharedPreferences("myPrefs", Context.MODE_PRIVATE); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With