I have two actions: A and B. When action A is first launched, it refers to the Intent passed to it (since Bundle is null , as it should be the first time), and accordingly displays information:
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 ... }
This works great for the first time. The EditText and ListView populated correctly.
Now, when an item in the list is clicked, action B starts to show the details:
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);
Right before B starts, the framework calls A overridden onSaveInstanceState() :
protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putSerializable("CustInfo", m_custInfo); }
In step B, when the Up button is pressed on the action bar, I want to return to activity A and be in the same state as before:
public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { Intent intent = NavUtils.getParentActivityIntent(this);
This is the problem when in the onCreate() activity A a second time, the Bundle parameter is null and getExtras() returns null . Since onSaveInstanceState() was called, I would expect the Bundle parameter to be non- null .
I read about this issue on other websites, tried suggestions, but nothing works.
android android-activity android-actionbar up-button
DavidCrow Jan 22 '13 at 15:47 2013-01-22 15:47
source share