我们可以在sharedPreferences
中使用BroadcastReceivers
吗?我想用service
重复receiving sms
interval = currentIntervalChoice
。为此,我有一个broadcastReceiver
。我在currentIntervalChoice
中存储了SharedPreferences
的值。我想要检索value
。但我在sharedpreferences.
收到错误
这是我的代码:
public void onReceive(Context context, Intent intent)
{
final SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,MODE_WORLD_READABLE);
if(isMyServiceRunning(context))
{
Toast.makeText(context,"service running", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(context,"service stopped", Toast.LENGTH_LONG).show();
int currentIntervalChoice = settings.getInt("currentIntervalChoice", 1);
ma.toggleLogging(AppSettings.getServiceRunning(context),
AppSettings.setLoggingInterval(context,currentIntervalChoice));
}
}