Note that there are some explanatory texts on larger screens.

plurals
  1. POShared Preferences not save data properly
    primarykey
    data
    text
    <p>Hello I have 3 activities in my app and I transport data between them with Intent. The problem that I ran into is that Shared Preferences I have on my main activity get change when I returned to the main activity from the 3 activity. I suspect that the problem is that my intent get reboot but I'm not sure. I'm trying to get the data remain the same as it was when i moved to the 3 activity. my app start in activity 1 then its going to the main activity and at last if you click a button its goes to the third activity get some data and returned to the main activity the problem I have is that the data I got form the first activity get restart when I returned from the third activity. when i move data between activities I use intent. </p> <p>my code to transport the intent activity 1:</p> <pre><code> Bundle CIW = new Bundle(); CIW.putInt("one", int1); CIW.putInt("two", int2); CIW.putDouble("double", double); Intent a = new Intent(Must.this, Main.class); a.putExtras(CIW); startActivity(a); </code></pre> <p>my code to get the bundles in my main activity (its in mine on create method):</p> <pre><code> Intent must = getIntent(); Intent name = getIntent(); Bundle CIW = must.getExtras(); Bundle card = name.getExtras(); int1 = CIW.getInt("one"); int2 = CIW.getInt("two"); double= CIW.getDouble("double"); int3 = card.getInt("three"); </code></pre> <p>my Shared Preferences code (on pause):</p> <pre><code> SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = settings.edit(); editor.putInt("one", Int1); //the rest of the variable editor.commit(); </code></pre> <p>my Shared Preferences code (on resume):</p> <pre><code> SharedPreferences settings = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); int1 = settings.getInt("one", int1); //the rest of the variable </code></pre> <p>my code to transport the intent activity 3:</p> <pre><code>Bundle number = new Bundle(); number.putInt("three", int3); Intent a = new Intent(Card.this, Main.class); a.putExtras(number); </code></pre>
    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.
 

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