[Android] [PATCH 2/8] extract database access to AsyncTask

Yu Lin yu.lin.86 at gmail.com
Tue Mar 4 23:33:40 CET 2014


---
 .../org/videolan/vlc/gui/PreferencesActivity.java  |   26 +++++++++++++++----
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index a3a4863..735a94d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -37,6 +37,7 @@ import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Environment;
 import android.preference.CheckBoxPreference;
@@ -143,8 +144,13 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
 
                             @Override
                             public void onClick(DialogInterface dialog, int whichButton) {
-                                MediaDatabase db = MediaDatabase.getInstance(getApplicationContext());
-                                db.clearSearchhistory();
+                                new AsyncTask<Void, Void, Void>() {
+                                    protected Void doInBackground(Void... args) {
+                                        MediaDatabase db = MediaDatabase.getInstance(getApplicationContext());
+                                        db.clearSearchhistory();
+                                        return null;
+                                    }
+                                }.execute();
                             }
                         })
 
@@ -159,10 +165,18 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                 .setOnPreferenceClickListener(new OnPreferenceClickListener() {
                     @Override
                     public boolean onPreferenceClick(Preference preference) {
-                        MediaDatabase.getInstance(getBaseContext()).emptyDatabase();
-                        BitmapCache.getInstance().clear();
-                        AudioUtil.clearCacheFolder();
-                        Toast.makeText(getBaseContext(), R.string.media_db_cleared, Toast.LENGTH_SHORT).show();
+                        new AsyncTask<Void, Void, Void>() {
+                            protected Void doInBackground(Void... args) {
+                                MediaDatabase.getInstance(getBaseContext()).emptyDatabase();
+                                BitmapCache.getInstance().clear();
+                                AudioUtil.clearCacheFolder();
+                                return null;
+                            }
+
+                            protected void onPostExecute(java.lang.Void v) {
+                                Toast.makeText(getBaseContext(), R.string.media_db_cleared, Toast.LENGTH_SHORT).show();
+                            }
+                        }.execute();
                         return true;
                     }
                 });
-- 
1.7.4.4



More information about the Android mailing list