Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it normal for the "activity.onCreate()" method to be called multiple times

Tags:

I have some code in the onCreate method an Activity and noticed that it is being called three times. Is it normal behaviour? Thanks.

like image 599
MyName Avatar asked Aug 27 '10 23:08

MyName


People also ask

Can onCreate be called multiple times?

OnCreate is only called once.

How many times does onCreate run?

You might want to read through the documentation on the Activity lifecycle. OnCreate will only be called one time for each lifetime of the Activity. However, there are a number of situations that can cause your activity to be killed and brought back to life. Thus, onCreate will be called again.

What is used of onCreate () method?

onCreate(Bundle savedInstanceState) Function in Android: When an Activity first call or launched then onCreate(Bundle savedInstanceState) method is responsible to create the activity.

What is the argument for onCreate function used for?

onCreate(Bundle) is called when the activity first starts up. You can use it to perform one-time initialization such as creating the user interface. onCreate() takes one parameter that is either null or some state information previously saved by the onSaveInstanceState .


1 Answers

You might want to read through the documentation on the Activity lifecycle.

OnCreate will only be called one time for each lifetime of the Activity. However, there are a number of situations that can cause your activity to be killed and brought back to life. Thus, onCreate will be called again.

To support this properly, you can save state information in onSaveInstanceState and restore it fron the state bundle you get in on create.

like image 171
Cheryl Simon Avatar answered Oct 13 '22 05:10

Cheryl Simon