Преглед изворни кода

Fix a cursor crash

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic пре 7 година
родитељ
комит
93643269a8

+ 6 - 3
app/src/main/java/com/nextcloud/talk/controllers/RingtoneSelectionController.java

@@ -80,6 +80,8 @@ public class RingtoneSelectionController extends BaseController implements Flexi
     private MediaPlayer mediaPlayer;
     private Handler cancelMediaPlayerHandler;
 
+    private Cursor cursor;
+
     public RingtoneSelectionController(Bundle args) {
         super(args);
         setHasOptionsMenu(true);
@@ -180,7 +182,7 @@ public class RingtoneSelectionController extends BaseController implements Flexi
                 manager.setType(RingtoneManager.TYPE_NOTIFICATION);
             }
 
-            Cursor cursor = manager.getCursor();
+            cursor = manager.getCursor();
 
             NotificationSoundItem notificationSoundItem;
 
@@ -212,8 +214,6 @@ public class RingtoneSelectionController extends BaseController implements Flexi
                     }
                 }
             }
-
-            cursor.close();
         }
 
         adapter.updateDataSet(abstractFlexibleItemList, true);
@@ -299,6 +299,9 @@ public class RingtoneSelectionController extends BaseController implements Flexi
     @Override
     public void onDestroy() {
         endMediaPlayer();
+        if (cursor != null) {
+            cursor.close();
+        }
         super.onDestroy();
     }