在接收器中使用共享首选项

时间:2013-04-15 11:35:35

标签: android broadcastreceiver sharedpreferences

我们可以在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));
        }
}

0 个答案:

没有答案