Mark--
I'm binding to the service and then starting it so that I can get
the notification of the propertyUpdate.
As far as dssShow not being assigned to:
in bindService(i, mConnection, Context.BIND_AUTO_CREATE);
mConnection is an instance of a ServiceConnection object that has a
onServiceConnected handler which is supposed to fire when the
connection is made (in my understanding). That code is copy pasted
from the SDK with minor tweeks:
protected ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder service) {
// This is called when the connection with the service has been
// established, giving us the service object we can use to
// interact with the service. Because we have bound to a explicit
// service that we know is running in our own process, we can
// cast its IBinder to a concrete class and directly access it.
dssShow = (DownloadShowsService)
((DownloadShowsService.LocalBinder)service).getService();
}
public void onServiceDisconnected(ComponentName className) {
// This is called when the connection with the service has been
// unexpectedly disconnected -- that is, its process crashed.
// Because it is running in our same process, we should never
// see this happen.
dssShow = null;
}
};
--Sean
Calendar: http://www.google.com/calendar/embed?src=darkmane%40gmail.com
Livejournal: http://darkmane.livejournal.com
Every 5 minutes you spend writing code in a new language is more
useful than 5 hours reading blog posts about how great the language
is.
On Sun, Jul 11, 2010 at 5:21 AM, Mark Murphy <[email protected]> wrote:
> On Sat, Jul 10, 2010 at 11:53 PM, Sean Chitwood <[email protected]> wrote:
>> Currently I have this code:
>>
>> Intent i = new Intent();
>> i.setAction(Intent.ACTION_RUN);
>> i.setClass(ShowDetail.this, DownloadShowsService.class);
>>
>>
>>
>> i.putExtra(Constants.TITLE_FIELD, mShow.getTitle());
>> i.putExtra(Constants.ENCLOSURE_FIELD, mShow.getMp3Path());
>> i.putExtra(Constants.NOTES_URL, mShow.getPdfPath());
>> i.putExtra(BaseColumns._ID, mShow.getId());
>>
>> bindService(i, mConnection, Context.BIND_AUTO_CREATE);
>> startService(i);
>> /* Make sure dssShow has been assigned to when we bind to it */
>> if(dssShow != null)
>>
>> {
>>
>> dssShow.addListener(new PropertyChangeListener(){
>>
>> public void propertyChange(PropertyChangeEvent event) {
>>
>> if(event.getPropertyName() == "finished" &&
>> (Boolean)event.getOldValue() == true)
>> {
>> ShowDetail.this.readShowData();
>> }
>>
>> }
>> });
>>
>> }
>>
>>
>>
>> The dssShow is always null immediately after the service starts.
>
> Based on the code you have listed here, that's because you're never
> assigning a value to dssShow.
>
> I am not quite certain why you are calling both bindService() and
> startService(). While there are occasional places where both are
> required, it is a bit unusual.
>
> Also, bear in mind that bindService() and startService() are both
> asynchronous.
>
> --
> Mark Murphy (a Commons Guy)
> http://commonsware.com | http://github.com/commonsguy
> http://commonsware.com/blog | http://twitter.com/commonsguy
>
> Android Training...At Your Office: http://commonsware.com/training
>
> --
> 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
--
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