Thursday, 15 April 2010

multithreading - How to pause and resume thread in android -



multithreading - How to pause and resume thread in android -

when userrecoverableauthioexception in abstractthreadedsyncadapter, i'm creating notification below.

here's how i'm creating service:

@override public ibinder onbind(intent arg0) { // todo auto-generated method stub log.i("service", "thread started"); homecoming this.getsyncadapter().getsyncadapterbinder(); }

private googletaskssyncadapter getsyncadapter() { if (syncadapter == null) { log.i("service", "syncadapter started"); syncadapter = new mysyncadapter(this); } homecoming syncadapter; }

once thread started, i'm raising notification. 1 time user clicks on notification, can see authorization activity. after authorising how resume lastly point. i.e how notified 1 time activity closed in syncadapter.

the syncadapter thread running, , want notification when syncadapter ends, right?

so, can comunicate syncadapter thread broadcast.

in syncadapter class:

intent = new intent(sync_finished); context.sendbroadcast(i); log.i(tag, "network synchronization complete");

in activity or fragment:

private broadcastreceiver syncfinishedreceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { log.d(tag, "sync finished!!"); // here can send notification or thing want } }; @override public void onstart() { super.onstart(); getactivity().registerreceiver(syncfinishedreceiver, new intentfilter(syncadapter.sync_task_finished)); } @override public void onstop() { super.onstop(); getactivity().unregisterreceiver(syncfinishedreceiver); }

note: sync_finished constant, can define in syncadapter

i hope i've helped you.

greetings!

android multithreading android-asynctask adapter android-syncadapter

No comments:

Post a Comment