0

I'm trying to pass data from the PreferenceActivity to the ControlExtension and I don't really know how to do that. I'm trying to use the BroadcastReceiver solution, because SharedPreferences doesn't work for my, but without knowing how yo use it so, ¿how and where I should register the BroadcastReceiver for the SW2?

Thanks in advance

EDIT:

I'm using now BroadcastReceiver but I ¿How do I have register my BroadcastReceiver in the ControlExtension? or ¿How do I start my ControlExtension from the ExtensionReceiver?

dortegaoh
  • 17
  • 3

1 Answers1

0

you can access shared preferences this way, e.g:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
int jpegQuality = Integer.parseInt( prefs.getString(mContext.getString(R.string.preference_key_jpeg_quality), "0") );

Set the mContext in your ControlExtension constructor, where you receive a Context.

peter.bartos
  • 11,855
  • 3
  • 51
  • 62
  • So, I did: `SharedPreferences preferences = mContext.getApplicationContext().getSharedPreferences("comandos", Context.MODE_MULTI_PROCESS);` and `public boolean onPreferenceClick(Preference preference) { preferences.edit().putString("amarillo", "amarillo").commit(); return true;}` on the preference activity onCreate and `prefs = PreferenceManager.getDefaultSharedPreferences(mContext); String comando = prefs.getString("amarillo","NULL"); if (comando.equals("amarillo")) Log.d(TAG, "amarillo");` onResume Control Extension and doesn't work – dortegaoh Jul 23 '14 at 07:40