Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning from an activity using navigateUpFromSameTask()
    text
    copied!<p>I have two activities, A and B. When activity A is first started, it accesses the <code>Intent</code> passed to it (because the <code>Bundle</code> is <code>null</code>, as it should be the first time through), and displays information accordingly:</p> <pre><code>CustInfo m_custInfo; ... protected void onCreate(Bundle savedInstanceState) { ... Bundle bundle = (savedInstanceState == null) ? getIntent().getExtras() : savedInstanceState; m_custInfo = (CustInfo) m_bundle.getSerializable("CustInfo"); if (m_custInfo != null ... } </code></pre> <p>This works fine the first time through. The <code>EditText</code> controls and <code>ListView</code> are filled out correctly.</p> <p>Now, when an item in the list is clicked, activity B is started to show the details:</p> <pre><code>m_custInfo = m_arrCustomers.get(pos); Intent intent = new Intent(A.this, B.class); intent.putExtra("CustInfo", m_custInfo); // CustInfo is serializable // printing this intent, it shows to have extras and no flags startActivityForResult(intent, 1); </code></pre> <p>Right before acivity B is started, the framework calls A's overridden <code>onSaveInstanceState()</code>:</p> <pre><code>protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putSerializable("CustInfo", m_custInfo); } </code></pre> <p>In activity B, when the Up button is pressed in the action bar, I want to return to activity A and have it be in the same state as it was before:</p> <pre><code>public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { Intent intent = NavUtils.getParentActivityIntent(this); // printing this intent, it shows to have flags but no extras NavUtils.navigateUpFromSameTask(this); // tried finish() here but that created an even bigger mess return true; } ... } </code></pre> <p>Herein lies the problem, when in <code>onCreate()</code> of activity A the second time, the <code>Bundle</code> parameter is <code>null</code> <strong>and</strong> <code>getExtras()</code> returns <code>null</code>. Since <code>onSaveInstanceState()</code> was called, I would have expected the <code>Bundle</code> parameter to be non-<code>null</code>.</p> <p>I've read about this issue on other web sites, have tried the suggestions, but nothing works.</p>
 

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