Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy My SharedPreference create another file name DATA_Preferences?
    primarykey
    data
    text
    <p>I have a listview with choice mode, and it working. I want to save that checked item to shared preference, then use it in another activity. But, my SharedPreferences doesn'nt save my string correct, and save another file call DATA_Preferences that i never call in my code. The result is my Next activity get wrong value..</p> <p>Here is my code that i use to save my string and call it use by another activity:</p> <pre><code>public void onClick(View v) { SparseBooleanArray checked = listView.getCheckedItemPositions(); ArrayList&lt;DBLokasi&gt; selectedItems = new ArrayList&lt;DBLokasi&gt;(); // Item position in adapter SharedPreferences prefs = getSharedPreferences("DATA_COOR", Context.MODE_PRIVATE); SharedPreferences.Editor prefsEditor = prefs.edit(); for (int i = 0; i &lt; checked.size(); i++) { int position = checked.keyAt(i); // Add slected if truee if (checked.valueAt(i)) selectedItems.add(adapter.getItem(position)); prefsEditor.putFloat(POINT_LATITUDE_KEY + i, Float.parseFloat(values.get(position).getLat())); prefsEditor.putFloat(POINT_LONGITUDE_KEY + i, Float.parseFloat(values.get(position).getLng())); } prefsEditor.commit(); String[] outputStrArr = new String[selectedItems.size()]; for (int i = 0; i &lt; selectedItems.size(); i++) { outputStrArr[i] = String.valueOf(selectedItems.get(i)); } Bundle b = new Bundle(); Location location = new Location("POINT_LOCATION"); for (int i = 0; i &lt; checked.size(); i++) { location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + i, 0)); location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + i, 0)); double latitude = prefs.getFloat(POINT_LATITUDE_KEY + i, 0); double longitude = prefs.getFloat(POINT_LONGITUDE_KEY + i, 0); prefsEditor.commit(); b.putDouble("Latitude" + i, latitude ); b.putDouble("Longitude" + i, longitude); } int banyakPilih = checked.size(); b.putInt("banyakPilih", banyakPilih); Intent intent = new Intent(getApplicationContext(), HasilPilihanActivity.class); // Create a bundle object b.putStringArray("selectedItems", outputStrArr); // Add the bundle to the intent. intent.putExtras(b); // start the ResultActivity startActivity(intent); } </code></pre> <p>I save my Prefernces in DATA_COOR.xml file name, it save my string, but i got another file that save my preference with file name DATA_Preferences in my Explorer. Some body can give me solution? Thanks before..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload