Questions tagged [oncreate]

onCreate refers to one of the lifecycle methods for several components on the Android platform.

The onCreate method is a lifecycle method of several Android components like Activities, Fragments, Services etc.

For activities and fragments, this is the first lifecycle method to be called when that component is first created. It can also provide a Bundle containing the component's previously frozen state, if there was one. This method is generally used to setup the component (for example in an Activity this would translate to creating the UI views, binding data to widgets etc).

More information can be found in:

995 questions
450
votes
9 answers

Android activity life cycle - what are all these methods for?

What is the life cycle of an Android activity? Why are so many similar sounding methods (onCreate(), onStart(), onResume()) called during initialization, and so many others (onPause(), onStop(), onDestroy()) called at the end? When are these methods…
Nav
  • 10,304
  • 20
  • 56
  • 83
373
votes
3 answers

Difference and uses of onCreate(), onCreateView() and onActivityCreated() in fragments

What are the differences between onCreate(), onCreateView(), and onActivityCreated() in fragments and what would they each be used for?
319
votes
5 answers

Start an Activity with a parameter

I'm very new on Android development. I want to create and start an activity to show information about a game. I show that information I need a gameId. How can I pass this game ID to the activity? The game ID is absolutely necessary so I don't want…
VansFannel
  • 45,055
  • 107
  • 359
  • 626
165
votes
2 answers

Difference between onCreate() and onStart()?

Possible Duplicate: Android Activity Life Cycle - difference between onPause() and OnStop() I was wondering - what is the difference between onCreate() and onStart() methods? I think that onStart() is a redundant method. onCreate() will ALWAYS be…
iTurki
  • 16,292
  • 20
  • 87
  • 132
155
votes
6 answers

Android: When is onCreateOptionsMenu called during Activity lifecycle?

I put a couple of breakpoints in onCreate (one at the beginning, and one at the end of the method), and I also put one at the beginning of onCreateOptionsMenu. The onCreate method is called first, and before it finishes onCreateOptionsMenu is…
Christopher Perry
  • 38,891
  • 43
  • 145
  • 187
130
votes
5 answers

What's onCreate(Bundle savedInstanceState)

Can anyone help me to know about the Bundle savedInstanceState in onCreate(Bundle savedInstanceState) I am newbie in Android. I try to understand it from developer.android.com. But I am not able to understand. Can anyone simplify it?
user1077015
  • 1,335
  • 2
  • 9
  • 5
123
votes
2 answers

Android onCreate or onStartCommand for starting service

Usually when I create an Android service I implement the onCreate method, but in my last project this does not work. I tried implementing onStartCommand, and this seems to work. The question is: when I have to implement a service which method is…
GVillani82
  • 17,196
  • 30
  • 105
  • 172
98
votes
4 answers

super.onCreate(savedInstanceState);

I have created an Android Application Project and in MainActivity.java > onCreate() it is calling super.onCreate(savedInstanceState). As a beginner, can anyone explain what is the purpose of the above line?
Pramod
  • 2,828
  • 6
  • 31
  • 40
96
votes
4 answers

Android - Activity Constructor vs onCreate

I understand that Android Activities have specific lifecycles and that onCreate should be overridden and used for initialization, but what exactly happens in the constructor? Are there any cases when you could/should override the Activity…
idolize
  • 6,455
  • 4
  • 24
  • 34
76
votes
2 answers

onCreate flow continues after finish()

I would like to finish an activity from inside the onCreate method. When I call finish(), onDestroy() is not immediately called, the code keeps flowing past finish(). onDestroy() isn't called until after the onCreate() closing brace. Per the…
flobacca
  • 936
  • 2
  • 17
  • 42
65
votes
3 answers

When does Application's onCreate() method get called?

In my Android application, I have a DefaultApplication class which extends android.app.Application, and in its onCreate() I bind some services which will be used by my other Activities in this app. Also I have a BroadcastReceiver which listens and…
Yasin YILDIRIM
  • 1,540
  • 2
  • 17
  • 29
59
votes
12 answers

Null pointer Exception - findViewById()

Can anyone help me to find out what can be the issue with this program. In the onCreate() method the findViewById() returns null for all ids and this causes a null pointer exception later. I can not figure out why the findViewById() can not find the…
user2629828
  • 685
  • 1
  • 8
  • 13
59
votes
2 answers

After the rotate, onCreate() Fragment is called before onCreate() FragmentActivity

I'm using FragmentActivity and Fragments. When the application starts: FragmentActivity onCreate() <------ FragmentActivity onStart() FragmentActivity onResume() Fragment onAttach() Fragment onCreate() <------ Fragment onCreateView() Fragment…
50
votes
3 answers

what is the different between onCreate() and onCreateView() lifecycle methods in Fragment?

I don't know when to use onCreate() or onCreateView(). I have used onCreate() and onCreateView() lifecycle methods. I think onCreate() for Activity and onCreateView() for Fragment. But I am not sure. Can I use onCreate() LifeCycle method in…
Cabezas
  • 9,329
  • 7
  • 67
  • 69
43
votes
3 answers

Using onCreate vs. onRestoreInstanceState

Is there technically any reason why I should use onRestoreInstanceState? Could I not do all the restoration in onCreate by checking if the savedInstanceState bundle is null? What is the primary benefit of using onRestoreInstanceState over doing…
Sean Hill
  • 1,297
  • 1
  • 13
  • 21
1
2 3
66 67