Question

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);

            }

        });

Calculated resut!

Navigated away and clicked back button

Results cleared

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top