OSDN Git Service

Switch to explicitly managed cursors for weather query.
authorDaniel Sandler <dsandler@android.com>
Tue, 27 Apr 2010 13:17:40 +0000 (09:17 -0400)
committerDaniel Sandler <dsandler@android.com>
Tue, 27 Apr 2010 13:17:40 +0000 (09:17 -0400)
Previously, DeskClock used Activity.managedQuery, which
didn't exactly leak cursors, but it allowed them to
accumulate as long as the DeskClock Activity was running.
When used overnight as a bedside clock, the Activity can run
for a very long time without being paused.

Bug: 2627720
Change-Id: If4d53d3d6cba9dd96b41a3e25f4c8fad75339c42

src/com/android/deskclock/DeskClock.java

index 625fa7f..f213ab8 100644 (file)
@@ -23,6 +23,7 @@ import android.app.PendingIntent;
 import android.app.UiModeManager;
 import android.content.BroadcastReceiver;
 import android.content.Context;
+import android.content.ContentResolver;
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
@@ -389,7 +390,7 @@ public class DeskClock extends Activity {
 
         Cursor cur;
         try {
-            cur = managedQuery(
+            cur = getContentResolver().query(
                 queryUri,
                 WEATHER_CONTENT_COLUMNS,
                 null,
@@ -447,6 +448,11 @@ public class DeskClock extends Activity {
                 mWeatherLowTemperatureString = "";
         }
 
+        if (cur != null) {
+            // clean up cursor
+            cur.close();
+        }
+
         mHandy.sendEmptyMessage(UPDATE_WEATHER_DISPLAY_MSG);
     }