I try to make a configuration activity using PreferenceActivity...
I found some working examples like
"WiFi Advanced Configuration Editor"
and
"Wifi Config Editor Pro"
but the code I wrote waits for 10-15 seconds on the line editor.commit()
...
it must be very simple but I cant figure out.
here is the brief code;
...
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(v.getContext());
prefs.registerOnSharedPreferenceChangeListener(ClassConfig.this);
SharedPreferences.Editor editor = prefs.edit();
editor.clear();
editor.putString("key1", value1);
editor.putString("key2", value2);
editor.putBoolean("key3", value3);
...
//i got nearly 35 keys here
...
editor.putString("key33", value33);
editor.putBoolean("key34", value34);
editor.putBoolean("key35", value35);
editor.commit();
Any ideas??
Update: one more thing. I saw these warnings in the log file
W/BackupManagerService(1914) dataChanged but no participant pkg='com.android.providers.settings' uid=10046
commit()
is executed synchronously, so you notice that it takes so much time..
Use apply()
instead.
https://stackoverflow.com/a/5960743/1233659
Committing large preferences is slow - it should be done in separate thread. Consider implementing this in AsyncTask
You should use apply()
method which is asynchronous. See docs here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With