Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid intent extra does not restore on resume
    primarykey
    data
    text
    <p>I have 2 activities, one sends data to the other by intent.</p> <p>I have 2 editText for users to input the value after saved, it will show in the editText box</p> <pre><code>savePreferences = getSharedPreferences("filename", Context.MODE_PRIVATE); first = savePreferences.getString("first", "1st"); second = savePreferences.getString("second", "2nd"); editf1.setText(first); editf2.setText(second); </code></pre> <p>In Activity1</p> <pre><code>public static String filename = "myfile"; SharedPreferences savePreferences; savePreferences = getSharedPreferences("filename", Context.MODE_PRIVATE); SharedPreferences.Editor saveEditor = savePreferences.edit(); saveEditor.putString("first", edit1.getText().toString()); saveEditor.putString("second", edit2.getText().toString()); saveEditor.commit(); Intent myIntent = new Intent(this, Activity2.class); myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //put the retrieved data in extras Bundle extras = new Bundle(); extras.putString("firststr", first); extras.putString("secondstr", second); myIntent.putExtras(extras); startActivity(myIntent); </code></pre> <p>In Activity2</p> <pre><code>Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { firstval = extras.getString("firststr"); secondval = extras.getString("secondstr"); } </code></pre> <p>I have 2 TextView to show the data passed from Activity 1</p> <pre><code>if (firstval == null || firstval == "") textView1.setText("empty"); else textView1.setText(firstval); if (secondval == null || secondval == "") textView2.setText("empty"); else textView2.setText(secondval); </code></pre> <p>When I clicked the save button the value is saved into shared preference and the intent will start and go to Activity2. At this stage, the value saved and passed from Activity1 are able to be shown in my TextViews.</p> <p>But once I refresh the page, the TextView show empty instead.</p> <p>When my application starts, Activity2 will start first and TextView show empty too. How do I make it such that when I open my app or refresh my app, the value of the intent extra is always there? instead of going to Activity1 to save it again.</p>
    singulars
    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