Issue
I am trying to save values while leaving from activity and retrieve when coming back to screen. So I'm using onSaveInstanceState method to save data and using Bundle object from onCreate method while coming back.
Below is my scenario..
Activity A:
protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
Log.d(TAG, "Object received from savedInstanceState");
}
else{
Log.d(TAG, "savedInstanceState value is null");
}
}
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
Log.d(TAG, "In onSaveInstanceState");
savedInstanceState.putString("obj_name", DashBoardDisplay_l.getName());
}
OnClickListener save_click = new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(getApplicationContext(),PointLogActivity.class);
i.putExtra("ref_name", Name_ref);
startActivity(i);}};
I could see the log for onSaveInstanceState method while leaving to PointLogActivity.
PointLogActivity:
@Override
protected void onCreate(Bundle savedInstanceState){
Intent intent = getIntent();
String YourtransferredData = intent.getExtras().getString("ref_name");
Log.d(TAG, "ref name "+YourtransferredData);
Name=YourtransferredData;
//For getting back button
getActionBar().setDisplayHomeAsUpEnabled(true);
}
I am coming back to Activity A by click back button in top left of the activity. But while coming back to Activity, I could not find date from Bundle object and getting log from null condition.
savedInstanceState value is null
So can someone tell where I am going wrong.
Solution
I resolved it by putting the below at parent activity in manifest file.
android:launchMode="singleTop">
Answered By - kpvsrkp
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.