Android Service, Keeping Track of Objects -


this kind of convoluted, please bear me. have object has imageview instance variable. image need attach object stored on server, , vary instance instance. therefore, need dynamically.

each object gets instantiated through oncreate() method of listactivity class. retrieve appropriate image, right after instantiation, have service role download correct image file server. stores image on sd card. far, good. file gets downloaded correctly.

here stuck. when service completes, need able link object intending file, file itself. accomplish this, trying pass along object service , broadcastreceiver. problem approach, have discovered, whenever pass along object, gets passed value, not reference. thus, new object created , trail destroyed.

i'm sure confusing. here relevant code. can post more if help. i'm open ideas how keep track of object or better ideas how accomplish this.

thanks in advance. know strange question. hope i've explained enough.

from oncreate() in listactivity:

//get image workout type system.err.println("workout: " + workout); intent intent = new intent(context, downloadpicture.class); intent.putextra("workout", workout); intent.putextra(downloadpicture.filename, filename); startservice(intent); system.err.println("service started"); 

the service

@override protected void onhandleintent(intent intent) {      workout callingobject = intent.getparcelableextra("workout");     system.err.println("onhandle workout: " + callingobject); //<--i can see different object pointer reference     string filename = intent.getstringextra(filename);     string urlpath = this.getresources().getstring(r.string.imagesurl) + filename;     //download file...  private void publishresults(workout callingobject, string filename, string outputpath, int result) {     intent intent = new intent(notification);     intent.putextra("workout", callingobject);     intent.putextra(filename, filename);     intent.putextra(filepath, outputpath);     intent.putextra(result, result);     sendbroadcast(intent);   } 

and in listactivity, broadcastreceiver. creates null pointer error, since object 'workout' null (if passed reference not null):

    private broadcastreceiver receiver = new broadcastreceiver() {          @override         public void onreceive(context context, intent intent) {             bundle bundle = intent.getextras();             if (bundle != null) {                 workout workout = bundle.getparcelable("workout");                 string filepath = bundle.getstring(downloadpicture.filepath);                 int resultcode = bundle.getint(downloadpicture.result);                 if (resultcode == result_ok) {                     system.err.println("download done: " + filepath);                     system.err.println(workout.getworkouttype().getdescription());                     workout.getworkouttype().setpicture(filepath);                     workoutsadapter.notifydatasetchanged();                          } else {                     system.err.println("download failed");                 }             }         }     }; 

i assume workout objects in adapter. in case can use workout object's index unique identifier.

instead of object itself, pass object's index when create intent send service. when service publishes results, correct workout object adapter index passed when calling service.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -