Mark Murphy (CommonsWare) helped me find the solution to this one.
Apparently in my manifest I had improperly specified that the receiver
and service should run in separate processes:
*snip*
<receiver android:name=".APITestIntentBroadcastReceiver"
android:process=":remote" />
<service android:name=".APITestIntentService"/>
<receiver android:name=".APITestBroadcastReceiver"
android:process=":remote" />
<service android:name=".APITestService" />
*snip*
Removing the android:process attribute from both of those service
entries resolved the issue. I could also have specificed the same
"named process" for the receiver and service and accomplished
something similar.
More information can be found at:
http://developer.android.com/guide/topics/manifest/receiver-element.html#proc
I was unaware of this process control. Neat!
On Dec 8, 1:07 pm, BK <[email protected]> wrote:
> Hi Dan!
>
> I was following the pattern proposed in Mark Murphy's book Advanced
> Android Development. Unfortuantely it appears that the static
> variable mechanism for state doesn't work as the BroadcastReceiver can
> run in a separate DalikVM than the Service, making the static variable
> instances completely different.
>
> This intrigued me:
>
> > * So, my BroadcastReceiver keeps a static Map<Long,WakeLock> ofWakeLocksit
> > creates when onReceive is called. It creates a new
> >WakeLockfor each call to onReceive, and generates a new unique ID
> > (hence the Long) for each one. The ID is sent as an Extra in the
> > Intent to the Service being fired. The Service, in onStart, creates
> > its ownWakeLock, then sends a "releasewakelock" Intent back to the
> > BroadcastReceiver with the same ID. When the BroadcastReceiver gets
> > that returned Intent, it releases theWakeLockstored in the map.
> > This method is a bit more complex than the public static, but does
> > allow the BroadcastReceiver and Service to reside in different
> > processes. Please let me know if this technique is harmful or bad in
> > some way. It seems to work for me.
>
> And indeed it does seem to work, but from the documentation:
>
> "A BroadcastReceiver object is only valid for the duration of the call
> to onReceive(Context, Intent). Once your code returns from this
> function, the system considers the object to be finished and no longer
> active."http://developer.android.com/reference/android/content/BroadcastRecei...
>
> This seems to indicate that the fact that the static Map is still in
> existence between broadcast calls is simply coincidence.
>
> Since I can find (or think of) no way to pass aWakeLockto any global
> or shared location for the BroadcastReceiver and Service both to use,
> I am stuck figiuring out how to make this work. I need to check more
> implementations out there and see what other people do.
>
> I'm in contact with Mark Murphy about this issue and we're trying to
> look through a few pattern examples and come up with one of our own.
>
> Cheers,
> bk
--
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