Android app entry point

When we develop an Android application, we always start with the onCreate() method of the main action. Obviously, before calling onCreate() you need to do some initialization. My question is: what is the entry point (or main method) of an Android application? What causes Dalvik VM in due time (i.e. when it finishes its initialization and is going to transfer control to the application)? Where can I find the code for this main ?

+8
android mobile dalvik
source share
4 answers

The first "entry point" is the application class that Kingston indicated.

However, the easiest way to get the first starting point is to check the stack when debugging onCreate.

You can check Instrumentation, this sound is somewhat similar to what you want.

http://developer.android.com/reference/android/app/Instrumentation.html

 MainActivity.onCreate(Bundle) line: 12 Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047 ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2627 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2679 ActivityThread.access$2300(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 125 ActivityThread$H.handleMessage(Message) line: 2033 ActivityThread$H(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4627 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 868 ZygoteInit.main(String[]) line: 626 NativeStart.main(String[]) line: not available [native method] 
+7
source share

You must extend the application class and override the onCreate method.

For reference: Application Class

+6
source share

I don’t know this myself, but that sounds an interesting question. This is the code that launches the new Activity and after the code, you are in the JNI code

 public void startActivityForResult(Intent intent, int requestCode) { if (mParent == null) { Instrumentation.ActivityResult ar = mInstrumentation.execStartActivity( this, mMainThread.getApplicationThread(), mToken, this, intent, requestCode); if (ar != null) { mMainThread.sendActivityResult( mToken, mEmbeddedID, requestCode, ar.getResultCode(), ar.getResultData()); } if (requestCode >= 0) { // If this start is requesting a result, we can avoid making // the activity visible until the result is received. Setting // this code during onCreate(Bundle savedInstanceState) or onResume() will keep the // activity hidden during this time, to avoid flickering. // This can only be done when a result is requested because // that guarantees we will get information back when the // activity is finished, no matter what happens to it. mStartedActivity = true; } } else { mParent.startActivityFromChild(this, intent, requestCode); } } 

Android source code is available, but it's a little difficult to get it because it is poorly documented. You will have to install repo and then download the framework/base project

+1
source share

In the main Java programs, we need the main () method, because when executing the byte code, the JVM (Java virtual machine) will look for the main () method in the class and start execution there.

In Android, the Dalvik virtual machine (DVM) is designed to search for a class that is a subclass of Activity and which is set as LAUNCHER to run the application from the onCreate () method, so there is no need for the main () method.

+1
source share

All Articles