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

Android: service destroyed when display is rotated

I've got a service that is running in a separate process. I'm finding that after the main process UI thread exits from onDestroy() that my service is being destroyed even though I've provided the application context with the binding and specified…
Syrinx
  • 51
  • 1
  • 3
5
votes
3 answers

Delphi - when to call DragAcceptFiles

I have procedure TMainForm.FormCreate(Sender: TObject); begin DragAcceptFiles (Handle, True ) ; end ; but the form does not accept dragged files - no drop cursor, no firing of WM_DROPFILES message. I had the following construct in my FormShow…
rossmcm
  • 5,493
  • 10
  • 55
  • 118
5
votes
0 answers

How to detect orientation changes but letting android handle them?

I have an issue very similar to this: Android - ActionBar not resizing with onConfigurationChanged ( AppCompat ) I need to let android handle orientation changes, because i want to get the activity recreated. But also, i need to detect when a…
5
votes
4 answers

Run code on first OnCreate only

I have a piece of code that I only want to run the very first time a particular OnCreate() method is called (per app session), as opposed to every time the activity is created. Is there a way to do this in Android?
AJJ
  • 2,004
  • 4
  • 28
  • 42
5
votes
1 answer

Run Android App Twice To Work, Why?

I'm making an android app that test if certain security features on your phone are enabled. For example, if you have password log in enabled or if your data is encrypted on your phone. For some reason, the app has to be ran twice to test and see if…
pHorseSpec
  • 1,246
  • 5
  • 19
  • 48
5
votes
1 answer

android - There is no default constructor for ArrayAdapter

I m making adapter to adapt my book collection to be visible in list view. Issue is solved if I add super(context, position): public BookAdapter(Context context, int position, List updatedBooksList) { super(context, position); …
ERJAN
  • 23,696
  • 23
  • 72
  • 146
5
votes
2 answers

Does the intent used to create an activity stick around?

A bit more on the question. I want to know if the data i passed in the intent that created an Activity stays around if I don't kill it. Example: Activity A calls Activity B with extra data String(SomeStringValue). Then Activity B calls C which Calls…
Raigex
  • 1,205
  • 12
  • 32
5
votes
2 answers

Activity did appear

I have a 3 Activities, and all of them has a a ViewFlipper with some images that keep running. The thing is that I load these images from the SDCard, and there are aproximatly 180 images. EVERY TIME I call one of these activities, it takes some time…
pedrofialho
  • 147
  • 1
  • 11
5
votes
1 answer

Android RatingBar onRatingChanged Listener

I am using a RatingBar element in my app, and im trying to set it up with an OnRatingChangedListener. In the listener, im doing different stuff using if statements on a variable. Problem is, for some reason when i have multiple options this listener…
rel-s
  • 6,108
  • 11
  • 38
  • 50
4
votes
1 answer

Android SQLite - why is my db re-created each time?

I'm trying to get a better understanding of the SQLiteOpenHelper class and how and when onCreate and onUpgrade are called. My problem is that each time I quit and start my application (technically it's actually each time I create a new instance of…
Louis Sayers
  • 2,162
  • 3
  • 30
  • 53
4
votes
2 answers

Getting an exception after rotating device in android becuase of absence of public construcotr method in Fragment class

I wrote a very simple program with one Activity that contains a fragment. I made the Fragment constructor to be private and i'm using static newInstance() method to return the fragment. The problem start when i'm rotating the phone. I'm getting an…
DorVak
  • 297
  • 2
  • 9
4
votes
1 answer

Android Application onCreate is not called before Activity onCreate

On Google Play I receive a NullPointerException when trying to access a static Application instance. It appears on different Android OS versions: Android 9, 8, and 6. From code it seems that Application.onCreate() hasn't been called or is called…
4
votes
1 answer

Side effects of calling Activity.setContentView() twice in a row

In my app I needed to call findViewbyId() from both onCreate() and from WebChromeClient.onCompletion(). To avoid findViewbyId() returning null I resorted to calling Activity.setContentView(int viewResID) before calling findViewbyId(). It works, but…
uTubeFan
  • 6,664
  • 12
  • 41
  • 65
4
votes
1 answer

Loading data during onCreate() via AsyncTask

I'm trying to load data during onCreate (also tried during onStart) via AsyncTask from a Room database. The thing is, I'm passing the context to the AsyncTask via a WeakReference and, sometimes (one out of four times) the context becomes null on the…
4
votes
2 answers

sqlite onCreate() problem I want my database created once,and it will not changed,but i can't create data when i'm in onCreate()

I want my database created once,and it will not changed,but i can't create data when i'm in onCreate()... public class EventsData extends SQLiteOpenHelper { private static final String DATABASE_NAME = "events.db"; private static final…
stelios
  • 1,027
  • 3
  • 14
  • 19