From 020551e88a9a38bc9377f84e5a08db2fba0d2689 Mon Sep 17 00:00:00 2001 From: gumartinm Date: Wed, 29 Feb 2012 08:00:22 +0100 Subject: [PATCH] Next step: create a background service. --- .../Test3/src/de/android/test3/Indexer.java | 2 +- .../src/de/android/test3/MobieAdHttpClient.java | 24 ++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Android/Testing/Test3/src/de/android/test3/Indexer.java b/Android/Testing/Test3/src/de/android/test3/Indexer.java index 91ad65b..89c9a56 100644 --- a/Android/Testing/Test3/src/de/android/test3/Indexer.java +++ b/Android/Testing/Test3/src/de/android/test3/Indexer.java @@ -56,6 +56,6 @@ public final class Indexer { * append a numeric note id to this Uri to retrieve an index */ public static final Uri CONTENT_ID_URI_BASE - = Uri.parse("content://de.android.test3.provider/index/"); + = Uri.parse("content://de.android.test3.provider/indexer/"); } } diff --git a/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java b/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java index f5e0c5d..beb90d7 100644 --- a/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java +++ b/Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java @@ -97,17 +97,23 @@ public class MobieAdHttpClient implements Runnable if ((uriInsert = updatedIndexer(objects)) != null) { try { downloadAds((String)objects.get("domain"), (String)objects.get("link"), (String) objects.get("id")); - } catch (Throwable e) { - //In case of any error, remove from the index database the stored file - //or the chunk successfully stored before the error. - this.context.getContentResolver().delete(uriInsert, null, null); - //Besides throw the original exception. - throw e; - } + } catch (Throwable e1) { + //In case of any error, remove the index database and the file + //or chunk successfully stored before the error. + try { + this.context.getContentResolver().delete(uriInsert, null, null); + this.context.deleteFile((String) objects.get("id")); + } catch (Throwable e2) { + // Log this exception. The original exception (if there is one) is more + // important and will be thrown to the caller. + Log.w("Error removing content after an exception.", e2); + } + //Besides throw the original exception. + throw e1; + } } - } - + } } catch (URISyntaxException e) { Log.e(TAG, "Error while creating URI from URL.", e); } catch (ClientProtocolException e) { -- 2.1.4