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
31
votes
3 answers

SQLiteOpenHelper failing to call onCreate?

I am trying to create a local database on an android phone using sqlite. I have a helper class, shown below, that is used to create the database and provide the "help". I am wanting to create an object of this class in the main part of my code and…
prolink007
  • 33,872
  • 24
  • 117
  • 185
31
votes
5 answers

What is a OnCreate method in android

I am new to android trying to understand what the below method does public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // load the layout setContentView(R.layout.filters); } My research…
user2910566
30
votes
1 answer

Access Fragment View from Activity's onCreate

I am in the process of making my first app for Android, and I have a Fragment that gets added to my Activity in the Activity's onCreate() method. The problem I am facing is that I am unable to find any of the views contained within the Fragment from…
Dan
  • 1,198
  • 4
  • 17
  • 34
29
votes
1 answer

requestFeature() must be called before adding content error on super.onCreate

I have an abstract class extending ActionBarActivity. In the onCreate, I have: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
ono
  • 2,984
  • 9
  • 43
  • 85
25
votes
5 answers

How to make notification resume and not recreate activity?

I thought I had this figured out, but after some debugging on this question: How to make notification uncancellable/unremovable I just realized my activity is still getting onCreated() and onDestroyed(), in random order. My manifest for the…
CeeRo
  • 1,142
  • 3
  • 12
  • 21
22
votes
10 answers

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

I have some code in the onCreate method an Activity and noticed that it is being called three times. Is it normal behaviour? Thanks.
MyName
  • 2,136
  • 5
  • 26
  • 37
21
votes
8 answers

"System services not available to Activities before onCreate()" Error message?

When the user hits an icon in my app, I want the app first to check if the device is connected to the internet and then do something depending on the result it receives (for know it's just popping up a dialog, informing whether the device is…
Igal
  • 5,833
  • 20
  • 74
  • 132
21
votes
2 answers

Android: Stop Recreating the activity on orientation change

I have a listview with two buttons in my main.xml layout. On click of one button i'am creating a textview dynamically and adding it at the bottom of the screen to confirm the user interaction. When the user clicks 2nd button (Confirm button), i need…
sachi
  • 2,122
  • 7
  • 30
  • 46
18
votes
3 answers

Saving Activity State in the onPause

I have a variable that I have successfully saved and restored using onSaveInstanceState @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // the UI component values are saved here. …
Waggoner_Keith
  • 590
  • 2
  • 9
  • 37
18
votes
2 answers

Can I startService from Application#onCreate()?

I want to start a service when my Application is initialized from whatever component. public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); startService(new…
Cedric Fung
  • 477
  • 1
  • 4
  • 12
18
votes
5 answers

Android: onCreate() getting called multiple times (and not by me)

There is something I don't quite understand right now. My main activity class creates a Service, which creates a new thread that waits for a TCP connection. Once one comes in, it will start a new activity: Intent dialogIntent = new…
James
  • 213
  • 1
  • 4
  • 8
18
votes
2 answers

java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener

I upgraded my android studio to 2.1.3. And now I am getting following error java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V in class…
Kuldeep Yadav
  • 1,664
  • 5
  • 23
  • 41
18
votes
2 answers

Should I restore savedinstancestate in onCreate or in onRestoreInstanceState?

I have an activity that starts some other activities for results, so when the result comes back, the activity may or may not have been destroyed and recreated. I have overridden onSaveInstanceState so as to add the data that needs to be preserved…
matteo
  • 2,934
  • 7
  • 44
  • 59
16
votes
7 answers

How can I know that OnResume comes after onCreate?

I have few activities and from one activity I open another and that go back to the first one... The point is onCreate is called ones , and onResume every time when the activity is show. For example when I close B that was previouslly started from A,…
Lukap
  • 31,523
  • 64
  • 157
  • 244
16
votes
2 answers

Android: Where to put activity's onCreate() code in a fragment?

I'm converting all my Activities to Fragments so that I can use them in a ViewPager. I've searched for this but I couldn't find a satisfying answer, so that's why I'm asking it here. In my Activities, I've written some code in the onCreate() method.…
Xander
  • 5,487
  • 14
  • 49
  • 77
1
2
3
66 67