Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are ZygoteInit calls?

Tags:

Periodically I get Exceptions reported on Android Market that aren't reproducible. The stack traces always begin like this:

at ... at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:143) at android.app.ActivityThread.main(ActivityThread.java:4306) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method) 

ZygoteInit$MethodAndArgsCaller appears to be calling app methods directly instead of through code. How is this happening?


Finally reproduced one of these exceptions as follows: touch app icon, touch text field to bring up dialog, press Home, kill app pid, touch app icon, and press Back. Added saving and restoring of app instances variables in onSaveInstanceState and onRestoreInstanceState to fix problem.

Would still like to find description of ZygoteInit calls somewhere.

like image 251
user877342 Avatar asked Aug 03 '11 20:08

user877342


People also ask

How does Android zygote work?

Zygote loads the core Java classes and performs initial processing of them. These classes can be reused by Android application and therefore this step makes them faster to start. Once the initial work of Zygote is done, the process listens to a socket and waits for requests.

How to start zygote?

init.rc starts the process "Zygote" via the program "/system/bin/app_process". Zygote loads the core Java classes and performs initial processing of them. These classes can be reused by Android application and therefore this step makes them faster to start.

What happens after the initial work of zygote done?

Once the initial work of Zygote is done, the process listens to a socket and waits for requests. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.


1 Answers

Lars Vogel describes the role of the Zygote process during Android's start up in this article:

During startup of the Android system the Linux kernel first calls the process "init". init reads the files "/init.rc" and "init.device.rc". "init.device.rc" is device specific, on the virtual device this file is called "init.goldfish.rc".

init.rc starts the process "Zygote" via the program "/system/bin/app_process". Zygote loads the core Java classes and performs initial processing of them. These classes can be reused by Android application and therefore this step makes them faster to start. Once the initial work of Zygote is done, the process listens to a socket and waits for requests.

like image 117
Alinium Avatar answered Oct 12 '22 13:10

Alinium