android - Passing value from Main Activity to Broadcast Receiver class on button click -


i want pass value mainactivity class broadcast receiver class. coding done in mainactivity.do have mention action("android.intent.action.airplane_mode") in manifest file also??

    public void broadcastintent(view v){                 if(togglebutton.ischecked()){                 intent i=new intent("android.intent.action.airplane_mode");                 string x="heyo";                 i.putextra("xx", x);                 sendbroadcast(i);                 }else{                 }    class x extending broadcastreceiver....              public void onreceive(context context, intent in) {                 // todo auto-generated method stub                  in.getextras();                 string action=in.getaction();                 if(action.equals("android.intent.action.airplane_mode")){                     string u=in.getextras().get("xx").tostring();                     toast.maketext(context,"hi " +u, toast.length_long).show();                  }else{                 toast.maketext(context,"intent detected", toast.length_long).show();             }             } 

use shared preferences. there tutorial that.

public void broadcastintent(view v){     activity activity = (activity) view.getcontext()     sharedpreferences sharedpref = activity.getpreferences(context.mode_private);     sharedpreferences.editor editor = sharedpref.edit();     editor.putstring("xx",x);     editor.commit();     intent i=new intent("android.intent.action.airplane_mode");     sendbroadcast(i); } 

and code of broadcastreceiver.

class x extending broadcastreceiver....              public void onreceive(context context, intent in) {             sharedpreferences sharedpref = context.getpreferences(context.mode_private);             string xx = sharedpref.getstring("xx", "");  } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -