Hi Mark, Could you please provide some pointers on how to implement listener object for the service.
Regards, Shekhar On Feb 16, 11:25 pm, Mark Murphy <mmur...@commonsware.com> wrote: > Shekharwrote: > > Now the service running in the background has to pass data to the > > activity continously for UI updates.For this I have > > written the following code > > > Intent intent = new Intent(Service.this, Activity.class); > > intent.putExtra("Data", data); > > intent.setAction(Intent.ACTION_ATTACH_DATA); > > sendBroadcast(intent,null); (Do I need to broadcast the intent???) > > > In activity I have done following things:- > > Implemented broadcast reciever: > > > private BroadcastReceiver mBroadcastReceiver = new > > BroadcastReceiver() > > { > > @Override > > public void onReceive(Context context, Intent intent) > > { > > if (Intent.ACTION_ATTACH_DATA.equals(intent.getAction())) > > { > > Bundle extra = intent.getExtras(); > > float Data[] = extra.getFloatArray("Data"); > > update(Data); > > } > > } > > } > > > Also registered the broadcast reciever in the OnStart function as > > below:- > > > public void onStart() > > { > > super.onStart(); > > IntentFilter filter = new IntentFilter(); > > filter.addAction(Intent.ACTION_ATTACH_DATA); > > registerReceiver(mBroadcastReceiver, null); > > } > > > Is this the right way of meeting my requirements. > > It's certainly one way. An alternative is to have the activity register > some sort of callback or listener object with the service, that the > service uses when events need to be propagated to the activity. That > will be more efficient and more private than your implementation, but it > involves a bit more code, usually. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://twitter.com/commonsguy > > Android App Developer Books:http://commonsware.com/books -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en