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

How to use create method with variables in Laravel

How can i define create method with variables and model in laravel? Like this: public function createMethodName($variable, $variable2) { \App\ModelName::create([...]); }
-2
votes
3 answers

Android Java onCreate

So I followed Google's first Android app sample. If I tapped the send button, it opened up the DisplayMessageActivity. But upon tapped the back button (left arrow) from the DisplayMessageActivity, the onCreate(Bundle savedInstanceState) of the…
user523234
  • 14,323
  • 10
  • 62
  • 102
-2
votes
2 answers

What is the default activity if you don't override onCreate?

I am new to both Android and Java (as well as OOP), so forgive me if this is super noobish. In going through the Android tutorial on a first app, the following code is written: @Override protected void onCreate(Bundle savedInstanceState){...} I…
NenTenEn
  • 11
  • 2
-2
votes
1 answer

A method returns null object when called from onCreate but returns correct value in onClick method

I am using wuapnjie/StickerView library in my app and one of the function getCurrentSticker in StickerView class is returning null object reference when I called the method in onCreate method, but working perfectly when called from any onClick…
Venkatesh
  • 41
  • 7
-2
votes
3 answers

Handle Screen Orientation?

When the page loads, first it loads in LANDSCAPE_MODE and then after a few seconds the orientation changes to PORTRAIT_MODE the value protected void onCreate(Bundle savedInstanceState) { super.onCreate(); …
-2
votes
3 answers

Getting Error while call a method from adapter class. java.lang.IllegalStateException: System services not available to Activities before onCreate()

When I try to call a method from my adapter class, I'm getting an error System services not available to Activities before onCreate(); MainTask.Class public class MainTask extends AppCompatActivity { public static final String mypreference =…
-2
votes
2 answers

Android adapter with GridView in Fragment

I created a soundboard with a GridView adapter, but I'm getting two issues. It says "CustomGridAdapter cannot be applied" myGridView.setAdapter(new CustomGridAdapter(getActivity(), items)); It says "Cannot resolve method itemClicked(int)" …
Aaron Waller
  • 175
  • 4
  • 21
-2
votes
2 answers

What should i write in parameter of a method in android

i am making an android application in which i want to pass "this" object of onCreate method in another method. What should i write in the parameter to catch that object correctly. Because i want to add objects into view. protected void…
Abhishek Panjabi
  • 439
  • 4
  • 23
-2
votes
1 answer

Error cannot resolve simbol list with list.setAdapter(adapter)

This is my code, it works at 100%: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View inflatedView = inflater.inflate(R.layout.t1, container, false); final ListView list =…
Question
  • 145
  • 2
  • 12
-2
votes
1 answer

extra activity created/onCreate() called when pausing app then resuming from lockscreen

when clicking the home button which exits my app and also calls onPause(), Then I re-open my app from a lock screen notification, onCreate() gets called even though the activity was never destroyed initially. which leads to the user having to press…
Andrew Irwin
  • 691
  • 12
  • 40
-2
votes
1 answer

Android Studio NPE warnings in onCreate

Lately Android Studio has started showing me unnecessary NPE warnings for views in onCreate. The app compiles and runs properly but it's quite distracting, for instance, when the whole textView.setOnClickListener block is highlighted in…
goat
  • 307
  • 3
  • 8
-2
votes
2 answers

How to call methods in onCreate (when the app starts)

I have MainActivity.class that has some methods. Here is the method I want to call when the app starts: public void loadGame(View view) { SharedPreferences loadGame = getSharedPreferences(PREFS, MODE_PRIVATE); …
-2
votes
1 answer

Pick a variable from onHandleIntent

I have a service class and I fetch data from an Intent in the method "onHandleIntent" and pick up in a variable. I would to call the value of this variable in onCreate, but when I call this variable I get a NULL value. (for examole in…
Giacomo Brunetta
  • 1,409
  • 3
  • 18
  • 38
-2
votes
1 answer

this.getWritableDatabase() is not calling onCreate()

I know similar questions have been asked many a time before; but after scrubbing through posts for hours, I haven't been able to find a solution. My implementation of SQLite refuses to work correctly, and the database is not being created, even…
Nikhil
  • 1
  • 2
-2
votes
2 answers

Is it proper to do the initialization in the constructor of an activity?

I am curious about what can I do in the constructor of an activity. Is it ok to do the initialization in the constructor? Thanks.
Tony Lin
  • 765
  • 3
  • 15
  • 35