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

onCreate vs onCreateView to integrate ActionBar-PullToRefresh

[UPDATE] I have add onCreateView but now i get this error : 07-03 14:39:36.878: E/AndroidRuntime(30913): FATAL EXCEPTION: main 07-03 14:39:36.878: E/AndroidRuntime(30913): java.lang.RuntimeException: Content has view with id attribute…
wawanopoulos
  • 9,614
  • 31
  • 111
  • 166
2
votes
3 answers

NullPointerException in onCreate of Activity

I have a splash page that opens up when my app is open, and then it is replaced by a LoginActivity that gives the option to the user of logging into Twitter with the app. This is the onCreate method of LoginActivity: protected void onCreate(Bundle…
user2163853
  • 907
  • 4
  • 14
  • 24
2
votes
1 answer

Why does my service calls its onCreate() itself while running?

I have a Service in my android application which stop only when quitting the application. public class MyService extends Service { public MyService() { } @Override public int onStartCommand(Intent intent, int flags, int startId) { …
Devu Soman
  • 2,246
  • 13
  • 36
  • 57
2
votes
3 answers

Android: avoid calling onCreate() when back from another activity

Assume my application contains two activity, A and B. Both are limited to portrait in AndroidManifest. Activity A started Activity B. In Activity B, there is a button, which calls finish() when clicked. The problem is... When I hold the device…
Peter Lo
  • 110
  • 1
  • 7
2
votes
1 answer

onCreate() in ContentProvider is not being called

onCreate() method in ContentProvider is not being called. Though when I click on a button, it goes inside insert() method and returns java.lang.NullPointerException. In onCreate() method I have only have @Override public boolean onCreate() { …
sattu
  • 632
  • 1
  • 22
  • 37
2
votes
1 answer

How to refresh a dialog Android

I made a dialog with builder.setSingleChoiceItem with array of items that a user can choose from. But when a user adds something to that array, the list in that dialog is not updated, showing the previous list. I read that you need to recreate the…
coolcool1994
  • 3,704
  • 4
  • 39
  • 43
2
votes
2 answers

updating the activity when the child activity close

I have an Activity stack like: activity A make something activity A call Activity B (without finish();) activity B make something activity B call activity C activity B finish(); activity C make something activity C finish(); i would like to…
2
votes
0 answers

OnCreate error - Gallery test(4.0.1)

this is my first question, but this forum helped me a lot in the last 2 months!!! I tried to make an "Gallery" on my Android app, i solved it for 1 Gallery, but after i tried to make more "Galleries", i got an error in my "OnCreate". This is my…
2
votes
0 answers

Sending message to an unbound Service in onCreate() method

I am developing an application and I need that when I leave the application (onPause ()) send a message to the service, using a bundle to save some data of my application. It works great. My problem is that when the application starts, it executes…
4gus71n
  • 3,717
  • 3
  • 39
  • 66
2
votes
0 answers

onCreate() called senseless amount of times when returning from another activity (Ice Cream Sandwhich)

I have an Android app which works fine with android 2.x but fails with Ice Cream Sandwhich. App has Mainactivity A which starts SetupActivity B with onStartActivityForResult() when "Setup" button is clicked. Via SetupActivity the user can start…
2
votes
3 answers

How to avoid execute some part of codes within onCreate()

I have a major problem dealing with onCreate() in Activity. Like the thread said, I can only execute some part of codes in onCreate() method of the main Activity once. So I followed the steps in that thread and do the following: /*I've updated the…
Iam619
  • 795
  • 2
  • 12
  • 28
2
votes
2 answers

Activity restarts my game on screen rotation (Android)

I know this question was already asked, but mine is a little different: I have 2 different layout files for my game; one for portrait mode and one for landscape. When I rotate the screen, the onCreate method restarts my game (creates all the…
Sebastian Breit
  • 6,137
  • 1
  • 35
  • 53
2
votes
2 answers

onResume not behaving as expected on return from other activity

I have a small app that calculates the time until a specified date and time. It works well. import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.concurrent.TimeUnit; import…
steve.watson128
  • 51
  • 1
  • 1
  • 7
2
votes
1 answer

new Handler in onCreate()

I'm instantiating my Handler for the UI thread in one of my Activity's onCreate() method. (To avoid memory leak risks, the Handler is not an inner class, it is a normal class.) Since one Handler corresponds to one Thread, but one Thread can have…
Thomas Calc
  • 2,994
  • 3
  • 30
  • 56
2
votes
4 answers

Android: how to use OnCreate() when pressing backbutton

When pressing the backbutton I want that, whatever screen will be loading, the onCreate() method will be executed. I want this because the screens must be refreshing when navigating through the app. Do I need to override the back button…
user1264255
  • 305
  • 1
  • 5
  • 13