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

how to know when the application comes to foreground in android

i am developing an android app in which i've used tabhost for tabbar in each tab i've hosted FragmentActivity which in turn hosts different fragments i am getting data from server via network calls and while sending each call i've to send the…
Khurram Shehzad
  • 1,010
  • 12
  • 16
0
votes
1 answer

Best way to use getString()

I'm having some problems on where and how to place and call the getString(). I tried at the beginning of my activity where I usually define it but always get an error. Should it be only after onCreate()? Some of my strings I use it very often so I…
Marcus Gabilheri
  • 1,259
  • 1
  • 14
  • 26
0
votes
1 answer

android: creating method in onCreate() running in onResume()

I've created a onClickListener in the onCreate() state. Once the program is running I'm in onResume() state, how come when I call the onClickListener in the onResume() state it works? Shouldn't there be a distinction between the states: import…
Carlo Luther
  • 2,402
  • 7
  • 46
  • 75
0
votes
1 answer

*Change activity background on application load (before onCreate)

I have the following problem: When I start my activity, its default background is set to white. I can change it in onCreate method. If I use this method to change the background, I have something like 2 seconds of white background every time I start…
Marek
  • 3,935
  • 10
  • 46
  • 70
0
votes
1 answer

Avoiding Call to OnCreate of background activity by pressing back of finish from Foreground Activity

I have two activity A and B. I am calling B activity from A by pressing a Button. But when i press back button from B activity or call finish then it calls onCreate of activity A. I dont know why it is happening. Both the activities have data.…
Varun Vishnoi
  • 328
  • 6
  • 23
0
votes
1 answer

unable to set content with existing layout

I am building an nfc read tag app. But i am unable to find set layout. problem in setContentView(R.layout.read); and txtRead = (TextView) findViewById(R.id.txt_read); Here is my code: protected void onCreate(Bundle savedInstanceState)…
0
votes
1 answer

Android MediaPlayer Seekbar not changing only tracking

I've got it set up with a random sound playing onCreate and I have to add a seekbar to track the audio, it moves with track but will not go back if seekbar is pulled back to another part in the audio. Any help would be great, only beginner, sorry…
user2407147
  • 1,508
  • 2
  • 22
  • 40
0
votes
0 answers

Android LifeCycle for Activities and thei subcomponents

I get from time to time in my app the following stacktrace from a crash: java.lang.IllegalStateException: System services not available to Activities before onCreate() at android.app.Activity.getSystemService(Activity.java:4463) at…
LeO
  • 4,238
  • 4
  • 48
  • 88
0
votes
2 answers

calling onCreate method from inside another method

I have never seen anyone explicitly call one of the system callback methods like onCreate() or onDestroy() from inside another method. It just looks wrong. I thought I saw this in some example and I can not believe it. Is it my imagination or was…
Kevik
  • 9,181
  • 19
  • 92
  • 148
0
votes
1 answer

How to stop setOnItemSelectedListener from running in onCreate

I set values in my setOnItemSelectedListener depending on what is selected in my spinner. How can I stop this method being called onCreate? Thanks in advance
cwiggo
  • 2,541
  • 9
  • 44
  • 87
0
votes
1 answer

Load Data setOnItemSelectedListener

Problem: I load my class, the setOnItemSelectedListener function runs and sets variable wattage to a specific value, depending on what item was selected in the spinner. How can I prevent this from happening, how can I include a custom value…
cwiggo
  • 2,541
  • 9
  • 44
  • 87
0
votes
1 answer

How to call a method with View param

I have a source code of an app for android which get location from network or gps. There is the next code: // Callback method for the "both providers" button. public void useCoarseFineProviders(View v) { mUseFine = false; mUseBoth = true; …
Víctor Martín
  • 3,352
  • 7
  • 48
  • 94
0
votes
5 answers

How to launch again the actual onCreate on Android?

For example, if i have a button called "Restart", and I want to launch again the onCreate where the app is actually.
Roberto
  • 35
  • 6
0
votes
3 answers

String doesn´t take value

I´ve got an onCheckedChanged that tells me if a RadioButton in a RadioGroup is pushed. RadioGroup rGroup = (RadioGroup)findViewById(R.id.rdgroup); // This will get the radiobutton in the radiogroup that is checked RadioButton…
user896692
  • 2,351
  • 7
  • 36
  • 57
0
votes
1 answer

AsyncTask re-executing onresume

I have this little problem. I fetch data from network into a ListView using AsyncTask. If I press on an item it takes me to another activity. Then, if I press the 'back' button, the AsyncTask does not execute again. (Which is exactly what I…