Thanks again Mark. I am exploring all 3 option one by one by searching examples on google. I will update here on status.
Thanks JC On Dec 22, 1:00 pm, Mark Murphy <[email protected]> wrote: > On Wed, Dec 22, 2010 at 2:13 AM, JC <[email protected]> wrote: > > thanks mark, > > > I am starting service in myactivity::OnDestroy. > > That is a bad idea, since onDestroy() is not guaranteed to be called. > > > When i am stopping service(2nd time activity get started and service > > running) I require latest value two integers from service. > > > How can i get those values in activity from service without waiting > > for service to stop? > > Option #1: Bind to the service, call some API method on the binder in > onServiceConnected(), unbind from the service, then call stopService() > in onServiceDisconnected() > > Option #2: Call startService() with some custom action string to > indicate "please send me the data" along with a Messenger tied to your > Handler, have the service send the data to the Handler via the > Messenger, and call stopService() when the data arrives. > > Option #3: Consider the data the service is generating to be part of > your data model and store it persistently, having the activity get the > latest data from the persistent store. > > There are probably many more options, but those should get you started. > > > One more question, In myactivity, i have handler which implements > > handlemessage(), is it possible to receive msg in it from service? > > Use a Messenger. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9 > Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

