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

Android service onCreate is called multiple times without calling onDestroy

In my app, I use a service to communicate with our server. The Service spawns several message queue threads to deal with tasks with different priorities. This model has been used for about one year without big issues. However, recently, I found some…
SXC
  • 237
  • 3
  • 8
15
votes
4 answers

Android onCreate onResume

I have a problem. When I start for the first time my android application, in the main activity both the onCreate and the onResume are called. but I want to be called only the onCreate. What can I do?
Alessio
  • 183
  • 1
  • 1
  • 4
15
votes
1 answer

Android: Save an instance state when app is closed

Possible Duplicate: How do I save an Android application's state? I am new to Java and Android and building some small projects to learn. I made a money tracking app which allows the user to input values and it simply continues to subtract it.…
user1218728
  • 159
  • 1
  • 4
14
votes
2 answers

Why is a call to finish() causing onCreate() to be called, starting a new Activity?

(Yes, I've already looked at existing questions related to this problem.) I am calling finish() from my Activity's Up button listener. But although onDestroy() does get around to being called, first onPause() is called and then, surprisingly,…
Alyoshak
  • 2,696
  • 10
  • 43
  • 70
14
votes
1 answer

Why is my onCreateView method being called twice?

While debugging another issue, I realized that the onCreateView method of one of my activities was being called twice. I'm new to programming and I don't fully understand how android calls these methods when the activity loads, but it doesn't seem…
NSouth
  • 5,067
  • 7
  • 48
  • 83
14
votes
6 answers

Where to set all Listeners?

Where to set all Listeners for the user interfaces? Is it good practice to set them in onCreate? This looks so unstructured and strange. Is there a better place to set them?
user2737037
  • 1,119
  • 1
  • 16
  • 29
13
votes
4 answers

Is onCreate called when an Activity object is created?

Is onCreate() called when a class object that extends Activity is created? Or is it only called when an activity is started, for example over startActivity(...)?
ShrimpCrackers
  • 4,388
  • 17
  • 50
  • 76
13
votes
6 answers

Android: Set Random colour background on create

What I want is when I load my app up it to randomly have a certain colored background from a predefined list of strings stored in a values xml file called colours. What I currently have is one colour set as the background defined through the string…
Phil3992
  • 1,059
  • 6
  • 21
  • 45
13
votes
4 answers

Android onCreate is called after locking the screen

When I lock the screen while my app is running "on top", the system calls almost immediately onCreate (screen is still black). What could be the reason for this destructive behaviour?
user2224350
  • 2,262
  • 5
  • 28
  • 54
11
votes
4 answers

Android SDK equivlent for viewWillAppear (iOS)?

Situation I have a fairly simple app with 2 "layouts" using SharedPreferences. Main.xml Settings.xml Main has a textView that uses getString from SharedPreferences. Also a button to open Settings. Settings has a spinner and a button to save to…
11
votes
5 answers

Why Bundle object is always null on onCreate()?

I am trying get into Android programming, and for I am taken some examples from a book. In on of these example is requested to put the following code: public class ExemploCicloVida extends Activity { /** Called when the activity is first…
André Barone
  • 141
  • 1
  • 2
  • 8
11
votes
3 answers

Image on start up / loading

I ma developing an app, which at the moment when it is loading from the onCreate point, I just have a black screen (until the app gets its footing). Looking at other apps they have a company logo or cool image that pops up for a few seconds, can…
Paul
  • 2,465
  • 8
  • 35
  • 60
11
votes
2 answers

OnCreate not called on Activity

I've created AbstractActivity and an AbstractFormActivity to rid of some boilerplate code, their content may be irrelevant to the question, but I will post it anyway, maybe I misunterstood something so, there they are: public abstract class…
Marcos J.C Kichel
  • 6,887
  • 8
  • 38
  • 78
10
votes
3 answers

onCreate of Content Provider

I found that onCreate of ContentProvider gets called first, even before the onCreate of my Activity. eg: Vogella Android SqlLite. But I wanted to know how does it happen and why? Is it because we register it as a provider in the Manifest?
Smitha
  • 6,110
  • 24
  • 90
  • 161
10
votes
1 answer

What is the exact difference between onAttachedToWindow and onStart

I sometimes see people using the Activity.onAttachedToWindow method but personally, I did never use it. When reading it's documentation it appears to me as it would be almost the same as onStart(). One thing I assume is: onAttachedToWindow is…
poitroae
  • 21,129
  • 10
  • 63
  • 81
1 2
3
66 67