Issue
When I navigate away from an activity with calculation results,for example to check the diagrams in the help activity and I select the back button in action bar,the calculation have been reset to null.
I know there must be some way of setting the state of the activity to pause
instead of having it stopped when I navigate away.
Does anyone know how I would achieve this in code? Is there a way to set the activity so that it doesn't destroy when the user leaves it? Also if I was to set this,would that calculation be fixed to that activity or would it refresh when I recalculate?
The code for the action bar back button is like this:
final Button actionBarHome = (Button)actionBarLayout.
findViewById(R.id.action_bar_title);
actionBarHome.setBackgroundResource(R.drawable.ic_action_back);
actionBarHome.setOnClickListener(this);
actionBarHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(intent2);
}
});
Solution
The activity lifecycle is out of your hands really. You should be handling resuming your activity yourself. Putting your data into the bundle of onSaveInstanceState and using the savedInstanceState Bundle in onCreate to repopulate your views.
You can refer to this article Recreating an Activity
Answered By - Dazzy_G
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.