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
7
votes
1 answer

onCreate, onCreateOptionsMenu, onResume, what is the order of execution?

I'm sorry if this question was asked before... Well anyway as what the title asked, when does onCreateOptionsMenu executed? before or after onResume? In my app, when the activity first run/opened the order will be onCreate --> onResume -->…
7
votes
2 answers

Android: using getIntent() only within onCreate?

In Android (targeting APIs 14-16) I have a MainActivity and a NextActivity. There is no difficulty using intents to start NextActivity from within MainActivity if the getIntent() method is called inside the onCreate() block of NextActivity: public…
brannerchinese
  • 1,909
  • 5
  • 24
  • 40
7
votes
7 answers

Why do OnCreate should be called only once on the start of Activity?

I would like to know, why OnCreate() is called only once at the start of an activity? Can we call OnCreate() more than once in the same activity? If yes, than how can we call it? can anyone give an example? Thanks a lot!!!
G M Ramesh
  • 3,420
  • 9
  • 37
  • 53
7
votes
1 answer

Log statements not being called in onCreate()

I have a series of Log statements in my onCreate() method for debugging, but sometimes they just aren't printed in my LogCat. Is there any reasoning for this that anyone is aware of? Maybe I'm misunderstanding the basics of an Activity's life…
JuiCe
  • 4,132
  • 16
  • 68
  • 119
6
votes
3 answers

How to cache views with Android and avoid calling onCreate everytime

I've got a question that is annoying me. With Android, I've got an application that seems to be calling onCreate every time a new instance of an activity is created, because this activity is the son of an another and it finishes itself while it ends…
EB- Iliass
6
votes
5 answers

Is there a problem with both overriding a Delphi form constructor, _and_ using it's OnCreate event?

Delphi help says either override a form's constructor, or use the OnCreate event. But don't do both. What's the reason for this? The only thing I can see, is if inherited is left out of the constructor in a descendant, TCustomForm.Create won't get…
6
votes
6 answers

Fragment in ViewPager returns empty object onResume

I use a FragmentPagerAdapter to switch from fragments. I need some functions to be called when a fragmentswitch is made and had some troubles with OnPause and OnResume, so as suggested by THIS question I have implemented an interface…
6
votes
1 answer

Android fragment OnCreateView called twice

I am using a FragmentPagerAdapter with fragments. My problem is that when I call setCurrentItem, the OnCreateView method of the fragment that is being loaded is called twice. It is important to note however that the fragment is not recreated, it is…
6
votes
2 answers

Android Application->onCreate() not called when reopen app

public class MyApplication extends Application{ @Override public void onCreate() { super.onCreate(); Log.d("*******:", "onCreate"); }} public class MainActivity extends ActionBarActivity{ @Override protected void onCreate(Bundle…
MichaelYe
  • 386
  • 4
  • 15
6
votes
1 answer

Can you please explain onCreate and Bundles?

I have been looking it up and I just cant seem to wrap myself around the onCreate and Bundles. I understand that the onCreate is called when the program starts but its how the Bundles get passed around and how they are pertinent. Can anyone try to…
Mike
  • 1,481
  • 6
  • 17
  • 22
6
votes
2 answers

Unable to instantiate activity caused by: java.lang.InstantiationException

@Bini this the error when i made your changes :( 09-26 11:06:05.620: D/dalvikvm(1613): Late-enabling CheckJNI 09-26 11:06:06.148: D/dalvikvm(1613): GC_FOR_ALLOC freed 51K, 4% free 3410K/3532K, paused 22ms, total 22ms 09-26 11:06:06.236:…
6
votes
1 answer

AndroidRuntimeException: requestFeature() must be called before adding content exclusive to Honeycomb 3.1 - 3.2.1

After last update my app has the following issue: java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.MyMainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding…
zilinx
  • 1,052
  • 8
  • 18
6
votes
3 answers

Which method is run when Home button pressed?

I have a Home replacement Activity from within which you can launch a number of apps. When you tap the Home button, you are returned to my Home replacement Activity. As I understand, tapping the Home button creates an intent to launch the Home…
mike
  • 1,318
  • 3
  • 21
  • 41
6
votes
3 answers

public onCreate(), or protected onCreate()?

While reading the "Hello, Android" book, I noticed that: each java file with onCreate(Bundle savedInstanceState) method, has protected access modifier EXCEPT in the main Activity of the program [that has: public void onCreate(Bundle…
Soroor
  • 109
  • 2
  • 7
5
votes
3 answers

What comes between onCreate and onStart for Android?

I see from Android Developers (http://developer.android.com/reference/android/app/Activity.html) that there is a nice flowchart showing onCreate leading to onStart then to onResume, and so forth. My question is: what other on****() methods appear…