Prevented crash in DownloadRequester when unbinding fails

This commit is contained in:
daniel oeh 2012-08-10 15:29:37 +02:00
parent 13f04e9fd9
commit 1c24794ed2

View File

@ -180,7 +180,7 @@ public class DownloadRequester {// TODO handle externalstorage missing
}
return false;
}
/** Checks if feedfile with the given download url is in the downloads list */
public boolean isDownloadingFile(String downloadUrl) {
for (FeedFile f : downloads) {
@ -255,8 +255,12 @@ public class DownloadRequester {// TODO handle externalstorage missing
if (AppConfig.DEBUG)
Log.d(TAG, "Connection to service established");
mService.queryDownloads();
if (mContext != null) {
mContext.unbindService(mConnection);
if (mContext != null && mIsBound) {
try {
mContext.unbindService(mConnection);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
@ -271,8 +275,7 @@ public class DownloadRequester {// TODO handle externalstorage missing
/** Notifies the DownloadService to check if there are any Downloads left */
public void notifyDownloadService(Context context) {
mContext = context;
context.bindService(new Intent(context, DownloadService.class),
mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
mIsBound = context.bindService(new Intent(context,
DownloadService.class), mConnection, Context.BIND_AUTO_CREATE);
}
}