3

If I create a new Intent of the same class every time I click a button, is the created activity the same?

Every time I click a button, I want to have a dialog show with a slider inside it and after I change it I want the state to be saved so that the next time I open up the dialog the state of the slider is the same.

My code for the button is this:

button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent(v.getContext(), Slider_Logic.class);
        v.getContext().startActivity(intent);               
    }
});
Blumer
  • 5,005
  • 2
  • 33
  • 47
Nikola Toshev
  • 135
  • 2
  • 10
  • You will have to pass additional Bundle parameters in order to save your state or the state of the slider. Meaning you will have to save the state somewhere then start the intent otherwise it will not make any sense it will have only your initial params for this class. http://stackoverflow.com/questions/768969/passing-a-bundle-on-startactivity – Sergey Benner Feb 28 '13 at 18:34

1 Answers1

2

By "same," I assume you mean the same object instance. The answer is no. In general, when you start a new activity, it creates a new instance of that activity and pushes it onto the stack in front of the existing activity.

I say "in general" because the activity's launch mode can effect this behavior. For example, if you set launchMode to singleTop, it will create a new instance of the activity if one doesn't already exist in the target task. Please see the docs for more information.

Blumer
  • 5,005
  • 2
  • 33
  • 47
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134