I really recommend not using a broadcast receiver for this. Generally this kind of thing is a 1:1 communication between the service and a client. It semantically isn't a broadcast it is sending to the world.
Instead, follow the LocalService example and just do the normal Java implementation of adding a callback that the service calls. Unless you are very careful, a broadcast receiver can open up a number of security holes in your app -- any other app could receiver the broadcasts you are sending, any other app could send broadcasts to you. You can prevent this from happening with careful use of permissions, but why bother? Just do a direct callback from the service to the client. On Thu, Oct 14, 2010 at 5:51 AM, Mark Murphy <[email protected]>wrote: > On Thu, Oct 14, 2010 at 8:38 AM, MobDev <[email protected]> wrote: > > An Activity (let's call it main) and a Service... > > The Activiy get's started right away, after which it couples to the > > Service. I'd liek the Service to be able to send broadcasts so that my > > Main (but other activities as well) can capture anything the Service > > has to say ;) > > Now I noticed though, that my Main activity cannot both include > > > > <activity android:name=".nowPlayingGUI" > > android:label="@string/app_name" > > android:screenOrientation="portrait" > > android:theme="@android:style/ > > Theme.NoTitleBar.Fullscreen" > > android:launchMode="singleTask"> > > <intent-filter> > > <action android:name="android.intent.action.MAIN" /> > > <category > > android:name="android.intent.category.LAUNCHER" /> > > </intent-filter> > > </activity> > > <receiver android:name=".nowPlayingGUI"> > > <intent-filter> > > <action > > android:name="development.android.service.musicServiceUpdate"></ > > action> > > </intent-filter> > > </receiver> > > > > thus it cannot start up as the MAIN activity AND be a receiver for a > > broadcast... > > Correct. > > > Is this correct, and how should I approach this problem to be able to > > accomplish what I have described at the beginning of the post ? > > Use a BroadcastReceiver. Register it using registerReceiver() from > your Activity, supplying a suitable IntentFilter. Unregister it via > unregisterReceiver(). > > Here is a sample project demonstrating this: > > http://github.com/commonsguy/cw-android/tree/master/Service/WeatherPlus/ > > -- > Mark Murphy (a Commons Guy) > http://commonsware.com | http://github.com/commonsguy > http://commonsware.com/blog | http://twitter.com/commonsguy > > Android Training in London: http://skillsmatter.com/go/os-mobile-server > > -- > 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]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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

