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

Android Usb Host, singleInstance, onCreate keeps getting called with USB attach

I have an application that uses a proprietary USB device (android in host mode). I have a BroadcastReceiver which I register in the constructor // this block is in the constructor usbConnectionReceiver = new UsbConnectionReceiver(); IntentFilter…
jo phul
  • 639
  • 1
  • 9
  • 29
4
votes
1 answer

Android - is onStart() called immediately after onCreate()?

If I have two activities A and B. And I create an intent that initiates activity B from the onCreate() of activity A, when will the onStart() of activity A be called? For example, let us say I had the following: public void onCreate(Bundle…
John Doe
  • 397
  • 3
  • 18
4
votes
3 answers

What method fires on AlertDialog creation?

What method fires on AlertDialog creation? Like onCreate() for Activities, My case: I have a fragment, and in this fragment i have a button with this setOnClickListener() Method : btnAddPromotionAw.setOnClickListener(new View.OnClickListener() { …
deuxdeux
  • 63
  • 9
4
votes
1 answer

Android tab fragment not calling OnCreateView switching from tab2 to tab1

This is the autogenerated code from android studio when selecting a 3 tabbed layout. The problem is when it starts at the first tab, it will call onCreateView in class PlaceholderFragment. When i switch to the 2nd tab, it calls it again for that…
Zoltar
  • 232
  • 1
  • 4
  • 10
4
votes
3 answers

The proper way of instantiating and initializing objects in android

I have several packages in my android project containing a number of classes. When I want to create an object of a certain class in a UI activity, I had used a method of creating a private object and initialize it before the onCreate() method where…
vidulaJ
  • 1,232
  • 1
  • 16
  • 31
4
votes
2 answers

onCreate called when back from background

Android documentation states that regarding the onCreate method: Called when the activity is first created. This is where you should do all of your normal static set up: create views, bind data to lists, etc. This method also provides you with a…
Vincent
  • 1,013
  • 14
  • 33
4
votes
1 answer

Android onCreate Service called when Activity onDestroy called

I have an activity that starts a service. If I exit to home screen and then from the recent apps list manually close the activity, onCreate is called again in the service. So when the activity is destroyed, onCreate is called again (even though the…
MobileMon
  • 8,341
  • 5
  • 56
  • 75
4
votes
4 answers

onCreate() called while Activity is stopped (but not destroyed). Only after installation

I'm working on an app that targets Api 19, and that is basically a Processing sketch. The problem I'm facing is that the first time my app is run, right after installing it, it works well until the user sends it to the background. Then, if they…
Kajuna
  • 449
  • 5
  • 20
4
votes
1 answer

Clicking Android notification creates a new activity instead of going to existing one

My app has a single running activity that creates a notification. When the notification is selected, instead of going to the running activity, the running activity is destroyed and a new activity is created - IN ANDROID 3.0 AND HIGHER. How do I…
D P
  • 41
  • 1
  • 4
4
votes
0 answers

Getting MenuItem in onCreate

When I'm trying to edit a MenuItem into a Progressbar (when downloading some stuff in the background of my app) it work well, but sometimes(after a check in the onCreate of my MainActivity) I wanna download something as well. So the problem is when…
4
votes
5 answers

which one is called first static block or oncreate method?

I want to know which is executed first static block or Oncreate method public class MainActivity extends Activity { static{ // dosomething } @Override protected void onCreate(Bundle savedInstanceState) { …
Shakeeb Ayaz
  • 6,200
  • 6
  • 45
  • 64
4
votes
3 answers

Can't create SQLite database in my android app

I'm using my application object(Android building bloc) to call the database constructor inside my oncreate method. But i can't figure out why it can't be created. This is how my code looks like: my database class, with DbHelper as an inner…
Saf
  • 227
  • 3
  • 11
4
votes
5 answers

where is the correct place to put onclick listeners in android Activity?

where is the best place to put onclick listeners in android activity? I have seen two different ways. one way is to put them inside the onCreate method, and another way is to put them below and outside the onCreate method. I just started a new…
Kevik
  • 9,181
  • 19
  • 92
  • 148
4
votes
3 answers

Android & AdMob: When to call AdView.loadAd

when is the "best moment" to load a new ad from AdMob? I'm programming a shopping list application that has an admob banner on its main screen. First I called m_AdView.loadAd(new AdRequest()); in the the onCreate() method. But so I always got…
Christian Graf
  • 406
  • 2
  • 10
  • 26
3
votes
4 answers

Android onCreate is not being called?

The problem is onCreate() is not being called! I really have no idea what the cause is, but I know that the Log.d()'s are not being called in onCreate() and in onSurfaceCreated(). I am trying to use OpenGL ES to make a triangle from a book I am…
Zeveso
  • 1,274
  • 3
  • 21
  • 41