java - How to send data via intent from an Activity to Service - Null Pointer Issue -


i'm trying pass info activity service.

i'm getting null pointer exception in logcat. i'm new remember reading on it's because intent.getstringextra null in service. i'm not sure that's case. can please tell me actual problem because i've tried everything. can't use bundle extras = this.getintent().getextras(); how else can solve problem .

below have in activity

         flashbutton1.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             // todo auto-generated method stub              strobediv++;              try {                  intent i1 = new intent(lelauncher.this, flashserv.class);                 bundle b = new bundle();                  totalms = string.valueof(totalmilli);                 cdms = string.valueof(totalmilli);                 strobedivstring =string.valueof(strobediv);                  b.putstring("totaltimemilli", totalms);                 b.putstring("cdtimemilli", cdms);                 b.putstring("strobediv", strobedivstring);                  i1.putextra("totaltimemilli", totalmilli);                 i1.putextra("cdtimemilli", cdmilli);                 i1.putextra("strobediv", strobediv);                   i1.putextras(b);                 lelauncher.this.startservice(i1);                 flashtext1.settext("seconds left: 1");              } catch (exception e1) {                  e1.printstacktrace();              }          }     }); 

below have in service.

@override public int onstartcommand(intent intent, int flags, int startid) {       //string totaltimemilli182 = intent.getstringextra("totaltimemilli");     //string cdtimemilli182 = intent.getstringextra("cdltimemilli");     //string strobedivstring182 = intent.getstringextra("strobediv");       bundle b=intent.getextras();       string totaltimemilli182 =  b.getstring("totaltimemilli");      string cdtimemilli182 =  b.getstring("cdltimemilli");      string strobedivstring182 =  b.getstring("strobediv");       footimetotal = integer.parseint(totaltimemilli182);     foocdtotal = integer.parseint(cdtimemilli182);     strobediv = integer.parseint(strobedivstring182);      strobetimer182();      return start_sticky;  } 

activity.java

intent intent=new intent(servicesactivity.this,filemanagerrequest.class);          bundle b=new bundle() b.putstringarray("array", your_array) intent.putextras(b); startservice(intent); in service 

service.java

    public void onstart(intent intent, int startid){     super.onstart(intent, startid);     bundle b=intent.getextras();     string[] array = b.getstringarray("array"); } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -