So I have a broadcast receiver that needs to notify a service that it has received a text message. The only way to do this (as far as I know) is a static method. But the method that is notified need access to the application’s preferences.
Every method I have tried says that it cannot be accessed from a static method. So how do I access preferences from a static method?
Hardly. In fact, that approach is not recommended.
If the service is supposed to be in memory when the broadcast is received, have the service register the
BroadcastReceiverviaregisterReceiver()and handle it directly. If the service is not supposed to be in memory when the broadcast is received, usestartService()to start the service and send over anIntent(picked up inonStart()of the service).See Pentium10’s answer.