Next step: create a background service.
authorgumartinm <gu.martinm@gmail.com>
Wed, 29 Feb 2012 07:00:22 +0000 (08:00 +0100)
committergumartinm <gu.martinm@gmail.com>
Wed, 29 Feb 2012 07:00:22 +0000 (08:00 +0100)
Android/Testing/Test3/src/de/android/test3/Indexer.java
Android/Testing/Test3/src/de/android/test3/MobieAdHttpClient.java

index 91ad65b..89c9a56 100644 (file)
@@ -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/");
     }
 }
index f5e0c5d..beb90d7 100644 (file)
@@ -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) {