android - AsynTask inside service: dealing with Screen Orientation -


i have trouble screen orientation when using asynctask it's inside service.
service like:

public class requestservice extends service {    private mybinder binder;          public requestservice(){     binder = new mybinder(requestservice.this); }  @override public ibinder onbind(intent intent) {     return binder; }  public class mybinder extends binder{     private final requestservice service;            public mybinder(requestservice service){         this.service = service;     }             public requestservice getservice(){         return this.service;     } }    public <t> void sendrequest(request<t> task, inotifyrequest<t> notify){     // call excute asynctask , notify result in onpostexcute     new taskexecutor<t>(task, notify).execute(); } } 

update: use service this:

 // start service  final intent intent = new intent(context, serviceclass);  context.startservice(intent);   // bound service:  final intent intentservice = new intent(context, serviceclass);  // implement service connection  serviceconnection = new requestserviceconnection();  context.getapplicationcontext().bindservice(intentservice, serviceconnection,                     context.bind_auto_create); 

when orientation changing, service unbound re-bound, asynctask doesn't notify update ui. i wonder why happen asynctask inside service?
have read this post, don't want lock screen orientation or that. prefer service intentservice service 's flexible, can use binder service instance.
so, question is, there way thread safe inside service rather asynctask?

if use bound service keep in mind, service destroyed if no activity bound. don't know if unbind in onpause(), destroy service @ orientation change.

because of loose service , reference asynctask. furthermore there no onretaininstancestate() available service, save asynctask , grab again.

think intentservice in case proper way. or if wanna keep service use startservice(), keep alive while no activity bound. can still bind , unbind service way want.

the next point keep reference of asynctask. because have set callback again if activity destroyed. because callback reference still set old activity.

hope helps.

edit:

well if read maybe consider using intentservice or something..

keep instance of asynctask in service , define setter in task callback. if activity binds service after orientation change check, whether asynctask running. if it's running update callback. can use binder that.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -