Reputation: 135
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);
}
});
Upvotes: 3
Views: 158
Reputation: 22637
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.
Upvotes: 2