android - PendingIntents keep caching same object -


i ve been facing problems trying pass data through intents , pending intents broadcastreceiver, concerning proximity alerts. more specifically, trying pass object, among others holds user's changing position. ve tried various tactics being proposed here (and not only) none worked, resulting either null values or same-as-first-time created intents, when intent retrieved on broadcastreceiver's side. tactics used:

  • flagging intent carries object with:flag_activity_new_task+flag_activity_clear_top+flag_activity_single_top result:null values on broadacastreceiver's side
  • flagging pending intent created using initial intent, with:flag_update_current or flag_cancel_current result:null values on broadacastreceiver's side
  • acquiring random id intent or pending intent using system.currenttimemillis(); result:intents not fired or received @ all
  • nothing described above. result:retrieving same initial value every time.

code calling method (stripped experimentations/producing null values):

private void setproximityalert(mycar mycar) {    string locservice = context.location_service;    locationmanager locationmanager;    locationmanager = (locationmanager)getsystemservice(locservice);   float radius = mycar.getmycarradius();    long expiration = mycar.getmycarexpiration();    myservice.setmydriverlat(userlat);//setting user's position   myservice.setmydriverlng(userlng);//setting user's position   intent  intent = new intent(mycar.getmycarname());   intent.putextra("mycar",mycar);    pendingintent proximityintent = pendingintent.getbroadcast(this, -1, intent, 0);   locationmanager.addproximityalert(mycar.getmycarlat(), mycar.getmycarlng(), radius, expiration, proximityintent);  } 

code calling method sets intent filter , registers broadcastreceiver:

public void addnewcarpoint (mycar mycar){         intentfilter filter = new intentfilter(mycar.getmycarname());         registerreceiver(new proximityalertreceiver(), filter);         setproximityalert(mycar);     } 

code broadcastreceiver's side:

public class proximityalertreceiver extends broadcastreceiver {  @override  public void onreceive (context context, intent intent) {  mycar mycar=(mycar)intent.getparcelableextra("mycar");   driverloc=(string)double.tostring(mycar.getmydriverlat());   toast.maketext(context, userloc, toast.length_short).show();   intent = new intent(context, mycardiscoveryprompt.class);   context.startactivity(i);//firing intent  }  public void intentdataloader(){        } 

}

any ideas more welcome. thank in advance.

hmm think ve found something:

i placed broadcastreceiver (proximityalerreceiver), used detect proximity alerts in same class (mycartracking.class), locationlistener.class located. this, provides immediate access fresh location updates, creating new intent wrapped in new pendingintent fired broadcastreceiver (only when proximity criteria met). flags:flag_activity_new_task+flag_activity_single_top , flag_cancel_current on intent , pendingintent, kept respectively. more specifically:

code locationlistener:

private final locationlistener locationlistener = new locationlistener() {          public void onlocationchanged(location location) {             updatewithnewlocation(location);//update application based on new location         }         public void onproviderdisabled(string provider){              updatewithnewlocation(null);//update application if provider disabled         }         public void onproviderenabled(string provider){             // update application if provider enabled         }          public void onstatuschanged(string provider, int status, bundle extras){              //update application if provider hardware status changed         }     }; 

code setproximityalert() method:

private void setproximityalert() {      string locservice = context.location_service;      context context =getapplicationcontext();     locationmanager locationmanager;      locationmanager = (locationmanager)getsystemservice(locservice);     float radius = mycar.getmycarradius();      long expiration = mycar.getmycarexpiration();      intent  intent = new intent(car_discovered);     intent.putextra("mycar",mycar);     locationmanager.getlastknownlocation(provider);     intent.addflags(intent.flag_activity_new_task).addflags(intent.flag_activity_single_top);//flagging intent     pendingintent proximityintent = pendingintent.getbroadcast(context, -1, intent, pendingintent.flag_cancel_current);//flagging pendingintent              locationmanager.addproximityalert(mycar.getmycarlat(), mycar.getmycarlng(), radius, expiration, proximityintent);//setting proximity alert } 

this solution works producing fresh intents fresh location updates. thank , interest :)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -