android - How to store string / integer value in Broadcast receiver.? -
i have 1 receiver extend broadcast receiver.i passing string value main activity. when activity create pass value receiver.i can receive string value. problem is, can not save string values.
i have tried shared preference context in broadcast receiver not working.
my receiver code here.
public void onreceive(context context, intent intent) { if(intent.getaction().equals("my.action.string")){ state = intent.getextras().getstring("value"); toast.maketext(context, "this state : " + state, toast.length_short).show(); sharedpreferences prefs = context.getsharedpreferences("myprefs", context.mode_private); editor editor = prefs.edit(); editor.putstring("state_lock", state); editor.commit(); p = prefs.getstring("state_type", state); toast.maketext(context, "the state type : "+ p, toast.length_short).show(); }
with code can data can not store them.
anyone can me. how can store data in broadcast receiver.?
thank in advance.
you saving data using "stae_lock"
key value , getting data using "state_type"
value stored use same key like
p = prefs.getstring("state_lock", state);
Comments
Post a Comment