Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Application onCreate method - does it ALWAYS get called first?

Tags:

android

I am preparing new version of one of my apps, and I made such huge changes in my app, that I need to do some data conversion exactly after update of app as absolutely first thing (before doing anything else). I figured out, that best place to do it would be in my class (which extends Application) in onCreate() method. I tested it few times, and it seems to work ok, but then I read documentation:

Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's tag, [b]which will cause that class to be instantiated for you when the process for your application/package is created[/b].

It looks like I am right, but I am not quite sure. Can you confirm/disprove it?

like image 548
qkx Avatar asked Jan 31 '14 15:01

qkx


1 Answers

The Application constructor will be called first. Then the Application::onCreate() method will be called. The only exception I know of is if the Application contains a ContentProvider, it can receive calls before the Application does.

This is from here: http://developer.android.com/reference/android/app/Application.html#onCreate()

public void onCreate ()

Added in API level 1 Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. Implementations should be as quick as possible (for example using lazy initialization of state) since the time spent in this function directly impacts the performance of starting the first activity, service, or receiver in a process. If you override this method, be sure to call super.onCreate().

like image 102
Dale Wilson Avatar answered Oct 06 '22 04:10

Dale Wilson