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

Android Java - OnCreate executes, but fails to create tables?

I'm working on my first Android project (full disclosure, this is a school project). I must confess I'm finding it to be much more convoluted than I expected. Anyway, here's my issue. I've created a DBHelper class: public class DBHelper extends…
M_J
  • 316
  • 5
  • 20
2
votes
1 answer

How to use onCreateView of AppCompatActivity

Background Info: I currently have an AppCompatActivity which is working. But right now, everything is in the onCreate method. I am concerned it is causing some little bugs I've been having lately with my PagerAdapter having…
Rock Lee
  • 9,146
  • 10
  • 55
  • 88
2
votes
0 answers

Android NFC always calling onCreate when app is open

I made app that detects nfc tag. All work fine when my app is closed and each time I start my app by touching nfc tag to my phone. 08-27 16:02:12.121 16692-16692/v2.nfc.android.com.nfcv2 D/MainActivity﹕ onCreate 08-27 16:02:12.121 …
David
  • 3,055
  • 4
  • 30
  • 73
2
votes
3 answers

Stop/Resume activities and onCreate in Android

I'm a new Android developer and I have a question. After users login, I need to get some data from an external URL and display them on one of my activities. But I've been reading and found this: When your activity comes back to the foreground from…
DandyCC
  • 353
  • 1
  • 6
  • 20
2
votes
1 answer

Android: onCreateView() runs from one tabs away

I am creating a tabbed app and I am running into a problem. onCreateView() runs when I click the tab next to where I am. What I mean is if I have three tabs (setup, maps, and motor) the onCreateView() view for maps and setup will run if I click…
user5016464
2
votes
2 answers

release memory when start new activity android

I didn't quite understand how starting a new activity works and how to release memory when doing that. This is what i have : Button b1, b2; @Override protected void onCreate(Bundle savedInstanceState) { …
cristi.gherghina
  • 311
  • 1
  • 6
  • 18
2
votes
4 answers

android newbie question null pointer on ArrayAdapter.setAdapter

I have been slowing learning and building my first android app. I'm VERY new to java but have already done a couple of projects in C#, VB.NET (back in the day), Objective-C (have 6 apps in the store) and Fortran (waaaaaaaaaaaaaaaaaaaay back in the…
2
votes
2 answers

onCreate param: 'savedInstance' is allways null

I'm learning basics of Android and I'm trying to save and retriever user preferences. I am using a physical device (Galaxy S4) to test the app. First I ensure the app calls the method 'onSaveInstanceState' @Override public void…
Nabuska
  • 443
  • 9
  • 17
2
votes
1 answer

When initializing a main window win32, when is the best time to show a modal dialog?

I'm trying to accomplish this in Win32, but I'm sure the same rules apply in the world of WinForms. Q: I create my main window, and then, when it is being shown, I want to show a modal dialog. The problem is; how can I know when the main window is…
l33t
  • 18,692
  • 16
  • 103
  • 180
2
votes
0 answers

Android: How to throw an exception from Service.onCreate?

I have a Service that needs do some work in it's onCreate, like open a file. However, if there is an IOException, onCreate should fail, how can I indicate this to the caller? The method doesn't throw any exceptions. I've tried using stopSelf(), but…
sjf
  • 785
  • 1
  • 8
  • 19
2
votes
0 answers

How the application object is called

In android app, if specify in the manifest with a class decedent from the Application, this class will be instantiated and its onCreate() will be called when start the app. And the default activity specified in the manifest will be…
lannyf
  • 9,865
  • 12
  • 70
  • 152
2
votes
2 answers

Open Navigation Drawer onCreate

I'm currently trying to implement a Navigation Drawer into my Application. For that i want the Drawer to be opened when the activity is started. This is my onCreate: @Override public void onCreate(Bundle savedInstanceState) { …
2
votes
2 answers

Rotate ImageButton onCreate without Animation

Is it possible to rotate an ImageButton using the onCreate() function? Or do you have to use an Animation which starts onCreate()? Because with an Animation i can see a little "flick" on Activity start...
Skyrisu
  • 373
  • 1
  • 5
  • 14
2
votes
2 answers

android username in action bar not displayed when page is loaded the first time

Hi I am very new to Android and I am having some issues with putting the username (retrieved by using the web services) into the Action bar. The problem is that the username is not displayed and is shown as 'null' when I first enter the page that I…
2
votes
1 answer

Adding listener to onStart vs onCreate

I'm trying to implement a button listener, and am able to if I do so in the onStart method. When I instead initialize in the onCreate (which I read is good practice), I'm receiving the error "Failed to update a TargetChangeListener"and the app…
Tom McFarlin
  • 829
  • 1
  • 9
  • 24