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

get activityInfo metaData in onCreate method

I need to retrieve a value from the AndroidManifest.xml file, stored as a meta data: In the onCreate method, I call the following method: private Object getMetaData(String name) { …
Julien
  • 157
  • 1
  • 2
  • 6
10
votes
3 answers

Error: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

I got a problem with my android app. I got a button and and event associated , but when I click the first time an error appears "spans cannot have zero lenght". . But when I click the second time, the event onclick runs well.. look at my java…
cpfp
  • 377
  • 1
  • 4
  • 15
9
votes
3 answers

Can I use setContentView outside the oncreate method?

I have seen many people telling that you can set setContentView outside the oncreate method, but I didn't find anywhere an example. Now when I try to use setContentView, my app just crashes. Here is my source code: AlarmActivity.java: package…
vicciu
  • 164
  • 1
  • 1
  • 10
9
votes
3 answers

After screen orientation change the dialogFragment appears apparently without any call

here there is part of the Activity where the screen orientation change: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et = (EditText)…
9
votes
3 answers

Getting intent extra and the onCreate method?

I have classes A, B and C. Class A sends intent to B, B runs C, C returns to B.....but then inside of the onCreate of the B class it wants the intent of Class A. But because its come from class C it does not get it but I still need the intent of…
user1876202
  • 361
  • 2
  • 3
  • 9
9
votes
6 answers

OnCreate method keeps getting called repeatedly

Update: Thank you all for attempting to help me solve this bug. I am still unsure as to the cause, I was able to roll back to a previous commit and continue development from there. This previous commit did show the same bug, however after I…
TheRealKingK
  • 829
  • 7
  • 14
8
votes
5 answers

Set Full Screen out onCreate

I can only set my Activity to Full Screen in onCreate method (before setContentView)? Is there any way I can set to full screen outside of onCreate? Thanks
fsilvestre
  • 299
  • 2
  • 10
8
votes
1 answer

Crashlytics crash report mentions XposedBridge

I released an update to an Android app yesterday, and today I am seeing a few crash logs in Crashlytics: Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.MyWebViewActivity}:…
Magnus
  • 17,157
  • 19
  • 104
  • 189
8
votes
1 answer

StrictMode disk read violation on empty activity's setContentView

I've recently tried to use StrictMode but got a weird violation, so I tried setting up a new 'Empty Activity' project (in Android Studio) and added an Application class as follows (as described in here): public class TestApplication extends…
MikeL
  • 2,756
  • 2
  • 23
  • 41
8
votes
2 answers

Set text of spinner before item is selected

I have a spinner with three items and I use an XML string-array resource to feed it. When you open an activity the spinner normally shows the first item that's in the array list. I'd like to change that and show the text "Select one" in the spinner,…
JohnD
  • 201
  • 2
  • 4
  • 12
7
votes
1 answer

How to restart the onCreate function

I have an application and there are certain conditions when I want my activity to be recreated or the onCreate function is needed to be called so that different functions can be performed again. Just like when the orientation of the device changes…
Farhan
  • 3,206
  • 14
  • 49
  • 62
7
votes
1 answer

How to run code on Application opens in Android?

My Android app need the user to create an account to be able to use the app. The account info is stored in SQLite database. When the application starts I check if the user has an account, if not I show a sign up activity for the user. Now I get…
Martin
  • 7,190
  • 9
  • 40
  • 48
7
votes
3 answers

Difference between getExtras(name).getString and getIntent().getStringExtra(name)

I have some error reports on my Android app, it's a Nullpointerexception in onCreate() in an Activity. The code that fails is getIntent().getExtras().getStringExtra("name"). (Nullpointerexception) That means that getExtras() is null somehow. I am…
Daniel Novak
  • 2,746
  • 3
  • 28
  • 37
7
votes
1 answer

Re-create database when using Content Providers

My Android App has a SQLite Database and a Content Provider. This Content Provider is registered in the app's AndroidManifest.xml. It is not exported, so only my app can see it. As part of resetting the user's profile, I want to completely wipe this…
Programmer001
  • 2,240
  • 2
  • 19
  • 35
7
votes
2 answers

Android - Activity onCreate and Fragment onCreate

I'm still new to Android programming, so this question is rather basic. I see lots of code samples on the Internet where UI components, like a TextView, are being initialised and accessed in the onCreate() method of an Activity. When I use Android…
Hippogriff
  • 295
  • 1
  • 4
  • 18