sharedpreferences

How to save dynamically added items in Listview with sharedpreferences?

不羁的心 提交于 2019-12-24 23:08:25
问题 protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); preferences = getSharedPreferences(FAVORI, 0); ListView favlist = (ListView) findViewById(R.id.favoriliste); ArrayList<String> foo = new ArrayList<String>(); String [] bar = foo.toArray(new String[0]); public void favekle(String string) { foo.add(string); bar = foo.toArray(new String[0]); favadapter = new MyFavAdapter(Diziler.this,

shared preference is deleted when application is closed

泄露秘密 提交于 2019-12-24 22:28:48
问题 i am building a log in screen using flutter and save user data in shared preference if it is right then i tested the saved data in the second screen and it has been already saved when the app is closed and open again i check the shared pref but it becomes null that's my saveData & getData Functions String namePref,phonePref, typePref,statePref; Future saveDataPref(String name,String phone, String type, String state )async{ SharedPreferences pref = await SharedPreferences.getInstance(); pref

how to share images inside assets folder with intent to other application

北战南征 提交于 2019-12-24 20:20:18
问题 i want to share images inside an assets folder using intent to the following applications hangout whatsapp line chat viber tango wechat i have try this code for whatsapp but it given me file not supported public void share (){ String file = "file:///android_asset/food/apple.png"; Uri filePath = Uri.fromFile(new File("content://com.example.zainabishaqmusa.postemoji/assets/gestures/aok.png")); final ComponentName name = new ComponentName("com.whatsapp", "com.whatsapp.ContactPicker"); Intent

PreferenceFragment: No view found for id android:id/prefs) for fragment

£可爱£侵袭症+ 提交于 2019-12-24 19:32:49
问题 I have a PreferenceActivity with a custom layout to keep a static header on top of all the items. I followed this thread to set this up: Adding a header to a PreferenceActivity <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/myCustomImageView" android:layout_width="fill_parent" android:layout_height="50dp" android:src="@mipmap/ic_launcher" /> <ListView android:id="

SQlite or Shared Preferences

≯℡__Kan透↙ 提交于 2019-12-24 14:53:02
问题 In my android app I receive data as json like this: "_playLists":[{"name":"Playlist 1", "items":[{"name":"Poza 1","target":"...","url":"...","url_thumb":"..."}, {"name":"Poza 2","target":"http:\/\/audifrance.fr","url":"...","url_thumb":..."}]}, {"name":"Playlist 2", "items":[{"name":"Poza 3","target":"...","url":null,"url_thumb":null}]}]} My question is : which is the best way to save data from this response: using Shared Preferences or using a database SQlite? Is it possible using Shared

Android PreferenceFragment in ViewPager

社会主义新天地 提交于 2019-12-24 13:00:24
问题 I have a MyPreferenceFragment that inherits from PreferenceFragmentCompat. This fragment resides inside a viewpager. I want the preference screen to have 1 EditTextPreference, "Name", and two preferences which should open up a new preference screen, "Mobile" and "Email". However, while all 3 shows up correctly, clicking "Mobile" or "Email" does nothing. How do i get it to open a new screen? From the documentation it seems like this should happen automatically when nesting PreferenceScreen.

Access shared preference from a service

[亡魂溺海] 提交于 2019-12-24 12:44:10
问题 I am fairly new to android. I have an activity in my application. I used shared preferences to store some data related to that activity. Now, how can I access those stored data from another service class? Is it possible? Your attention is highly appreciated. 回答1: Seeing as you're already in an application component that extends Context, you can simply use: SharedPreferences prefs = this.getSharedPreferences("Pref name", Context.MODE_PRIVATE); Make sure you call this in or after onCreate() .

Managing SharedPreferences in both PreferenceActivity and Service within same app

六眼飞鱼酱① 提交于 2019-12-24 12:03:11
问题 I'm building an app with a PreferenceActivity and a Service (running in its own remote process due to android:process=":remote" flag) and both need to access programmatically the SharedPreferences . At present time I'm getting a SharedPreference object with the following code that uses the getSharedPreferences method defined in both Service and PreferenceActivity classes: SharedPreferences sharedPrefs = getSharedPreferences("com.mypackage_preferences", MODE_PRIVATE, MODE_MULTI_PROCESS) Is

Getting shared preferences and displaying them in a listview

假如想象 提交于 2019-12-24 11:35:43
问题 So I have some shared preferences in my main activity: SharedPreferences prefs = this.getSharedPreferences("myFavs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); And I add some generated strings as a key value pair: editor.putString(saved,saved); editor.apply(); In another activity I would like to be able to display all the key value pairs I have saved in my shared preferences file into a ListView. I have used things like: ListView listView = (ListView) findViewById

How to save a JSON array into SharedPreferences and read again in a different activity. Android

不羁岁月 提交于 2019-12-24 11:28:27
问题 I need to save my Json Array into SharedPreferences and access it later in different Activity. here is the example of my Json : Array ( [status] => success [reason] => success [version] => 1 [total] => Array ( [category_1] => 3 [category_2] => 3 [category_3] => 3 ) [title] => Array ( [category_1] => Food [category_2] => Drink [category_3] => Dessert ) [data] => Array ( [category_1] => Array ( [0] => Array ( [content_id] => 123456 [name] => Name1 [title] => This is title one [desc] => This is