sharedpreferences

In shared preferences how to store string array in android application

南笙酒味 提交于 2019-12-18 03:49:02
问题 In my application am using list view in base adapter. when i click the item its id store in shared preferences string array format. how to save multiple item id in string array format [1,2,5,6] like this 回答1: You can try using JSONArray as JSON is light-weight also, you can create a JSONArray and write it to SharedPreference as String. To write, SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(this); JSONArray jsonArray = new JSONArray(); jsonArray.put(1); jsonArray

Security with SharedPreferences

穿精又带淫゛_ 提交于 2019-12-17 22:23:56
问题 I am developing an application in which I have to store very sensitive data and it should not come in contact with the user. I got to know from this source that if a device is rooted then accessing SharedPreferences and modifying it is a cakewalk. And I don't want it. So is there any method to protect my SharedPreferences from being accessed from anywhere. Or better still if some one can advise safer data storage option 回答1: There are different Points to consider: Shared Preference on an

Action Bar Home Button not functional with nested PreferenceScreen

耗尽温柔 提交于 2019-12-17 22:20:57
问题 I found a workaround to actually enable the ActionBar home button on the nested PreferenceScreen... however it doesn't call OnOptionsItemSelected in my PreferenceActivity. Anyone know a way to actually use the home button on a nested PreferenceScreen? Modification of post 35 here: http://code.google.com/p/android/issues/detail?id=4611 @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { super.onPreferenceTreeClick(preferenceScreen,

Google drive to back up and restore database and shared preferences of Android application

半腔热情 提交于 2019-12-17 21:57:11
问题 I need to create a backup of my application which would include creating a backup of 2 databases and also the shared preferences using Google drive API. I was able to get the authentication done for the app and also create a new folder in Drive using the following code: public class MainActivity2 extends BaseDemoActivity { DriveId folderId; @Override public void onConnected(Bundle connectionHint) { super.onConnected(connectionHint); MetadataChangeSet changeSet = new MetadataChangeSet.Builder(

PreferenceActivity: save value as integer

北城以北 提交于 2019-12-17 21:43:30
问题 Using a simple EditTextPreference in my preferences activity: <EditTextPreference android:key="SomeKey" android:title="@string/some_title" android:summary="..." android:numeric="integer" android:maxLength="2" /> Is there a way that this configuration value would be saved as integer? Seems now it just allows to enter numbers, but the value is still saved as string: Calling: SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); int value = preferences.getInt(

Saving an entire Bundle to SharedPreferences

巧了我就是萌 提交于 2019-12-17 21:02:06
问题 Assuming a method of mine was passed a Bundle already filled with data to be saved, is there a way to save it to SharedPreferences without taking it apart to ints, floats, Strings, etc.? I prefer the convenience of writing/committing it all in "one fell swoop", so if this isn't possible using SharedPreferences, what other persistent storage approach would you recommend? 回答1: as far as I know, you can save only primitive data (and their wrappers) to SharedPreferences why don't you create your

Get all SharedPreferences names and all their keys?

ⅰ亾dé卋堺 提交于 2019-12-17 20:20:00
问题 I'm making backup program, that saved the phone SharedPreferences data into a file of my own structure. But I don't know how to list them all, which I need: For example, 2 program saved their SharedPreferences with names "Program A" and "Program B" . I need to obtains thay String array contain these 2 names. Then, I use getSharedPreferences with "Program A", I need to get all keys that program has saved. Is it really possible? EDIT1: I DON'T know what programs/activities on the phone. I want

How to prevent a shared preference from being clear in setting

时光总嘲笑我的痴心妄想 提交于 2019-12-17 19:45:51
问题 I don't want to let Settings clear my app sharedPreference by anyone: is it possible? 回答1: hey buddy i found an answer here is a way to prevent data being cleared from Shared Preference Add android:manageSpaceActivity=".ActivityOfMyChoice" to the application tag of your Manifest like: <application android:label="MyApp" android:icon="@drawable/icon" android:manageSpaceActivity=".ActivityOfMyChoice"> Then instead of "Clear Data" , there is a button for "Manage Space" which launches

Making an activity appear only once, when the app is started

孤街醉人 提交于 2019-12-17 19:44:44
问题 I have the following class, SplashActivity.java : public class SplashScreen extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.splash); Thread timer = new Thread(){ public void run(){ try{ sleep(5000); }catch(InterruptedException e) { e.printStackTrace(); } finally{ Intent tutorial = new Intent(SplashScreen.this, TutorialOne.class); startActivity(tutorial); } } }; timer

NullPointerException in SharedPreferences Android

懵懂的女人 提交于 2019-12-17 18:53:16
问题 My first time using sharedPreferences and i can't seem to get past this error. I have a submenu that is supposed to allow the user to set their region. This should open the correct region activity and be stored and recalled when the app is opened again. I've been going round in circles many times so some of the code will be a bit wierd. I've been focusing on changing from US (default)to UK. In the DDMS I'm getting this: 05-13 11:22:39.344: ERROR/AndroidRuntime(960): java.lang