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
1
vote
1 answer

How to trigger fragment's onCreate method?

I have a ViewPager with 4 views. View #3 needs to respond to some broadcasted events. Hence, I register a custom BroadcastReceiver in onCreate as described here. This works if I make sure to show view #3, triggering the onCreate event. Otherwise, it…
l33t
  • 18,692
  • 16
  • 103
  • 180
1
vote
1 answer

Determining onCreate() VS onRestartingFromBackGround() in Android app

I'm having a small problem with the Android app I'm designing. I need to run some code whenever either of these 2 events happen: 1. The app is NOT running in the background, so the user launches it. 2. The app IS already running in the background,…
Carol
  • 407
  • 6
  • 14
1
vote
2 answers

Android - child activity updates database on onDestroy and parent reads on onResume

I have 2 activities A->B. A is the parent activity and B is like "settings". In B the user makes some choices that update the app's database. A has to read the database to set some textviews in accordance to that. What I thought would work is this:…
george
  • 1,386
  • 5
  • 22
  • 38
1
vote
3 answers

How to resolve NullPointerException in an Activity when calling super class onCreate() method in Android

Hi Friends i have written an Activity like below. SplashScreen.java public class SplashScreen extends Activity { protected final int _splashTime = 4000; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
user1195614
  • 385
  • 2
  • 8
  • 20
1
vote
2 answers

Android Sliding Drawer Open On Create

I want to have a slider that is open when the app starts. It will be open with buttons and such and when the user closes it, there will be more buttons to access. Is this possible with a sliding drawer? What would I add to the onCreate()…
mkyong
  • 12,497
  • 12
  • 37
  • 56
1
vote
4 answers

Custom AlertDialog fails to initialize in onCreate()

I'm trying to build a custom AlertDialog by extending the AlertDialog class. As usual, I'm setting up the dialog inside its onCreate() method. Or, I'm trying to do so: @Override protected void onCreate(Bundle savedInstanceState) { …
JimmyB
  • 12,101
  • 2
  • 28
  • 44
1
vote
2 answers

Helper Class - Error Unable to start activity ComponentInfo:

Error Unable to start activity ComponentInfo: java.lang.IllegalStateException: System services not available to Activities before onCreate() I´m experimenting with seperating the code and the use of a helper class. (Created different Java…
Diego
  • 4,011
  • 10
  • 50
  • 76
1
vote
1 answer

Local Service Binding Code from Activity to Service

The client code for binding to a service, which is normally in the activity class; I'm trying to move it to the service class, so that the activity class would be as clean and small as possible. i.e. basically trying to merge the code in the second…
Cel
  • 6,467
  • 8
  • 75
  • 110
1
vote
2 answers

ANDROID activity force stop on restart

I've looked through a lot of other threads about this but haven't had any luck yet with their solutions. When I launch my app for the first time, I noticed that onResume is being called after onCreate. (not sure why) My problem is when I try to run…
user980058
  • 511
  • 7
  • 18
1
vote
2 answers

Exchange data between activities without using oncreate

I have realized one application with Android which contain two parts (activities) 1- Main activity receive GPs, calculate X,Y pixels on a Map 2- Showing/scrolling map after loading it from SD card. The exchange between both activities is made every…
1
vote
1 answer

Activity gets killed but saved bundle is not received in onCreate

I have an application that works without fragments. I modified an activity to use fragments. The problem is that now when the activity goes in background and then in foreground again the onCreate is called: it looks like the activity gets killed to…
kingston
  • 11,053
  • 14
  • 62
  • 116
1
vote
1 answer

"If" in OnCreate fails

In my onCreate I am setting myString = getIntent().getStringExtra("sentString"); and after that if (myString == "test") {...} fails to execute... even though afterwards btnTest.setText(myString); Works What is the problem?
Daniel
  • 1,064
  • 2
  • 13
  • 30
1
vote
1 answer

Android Activity.onCreate is called twice when using foreground NFC dispatching

My Activity.onCreate() method is called twice when I use foreground NFC dispatching and re-install my app after force-stop. Detailed steps to reproduce this bug: Create the following Activity: package com.example.sample class MainActivity :…
Xeniale
  • 11
  • 2
1
vote
3 answers

application crashes on orientation change while using progressDialog with threading

--> I've implemented threading in my first activity. And made the use of progress dialog also. So now during the orientation (of that screen only) my application crashes - gives exception of memory Leaked. And as a solution of this I came to know…
Ravi A
  • 505
  • 1
  • 5
  • 16
1
vote
1 answer

Why starting the Activity by an intent (Intent.ACTION_VIEW) doesn't always start a new activity and call onCreate()?

I have two Android applications. The first application is the "browser". It gets an URL and displays it in a WebView. The corresponding activity is declared as:
vmayorow
  • 630
  • 5
  • 15