29

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.

casperOne
  • 73,706
  • 19
  • 184
  • 253
user877342
  • 301
  • 1
  • 3
  • 5
  • Is it possible you have orphaned listeners setup that are trying to invoke a callback and that is what you are seeing as being directly called?.. the trace doesn't seem all that odd to me. – Quintin Robinson Aug 03 '11 at 20:12
  • 1
    The app implements View.OnClicklistener.onClick(View). However the stack trace doesn't start with the switch in onClick; it shows only a method call in one of the cases, not even the first method in the case. Also, methods in another case have to run first. The log of normal operation never shows any calls to ZygoteInit. That's what makes the trace seem odd to me. – user877342 Aug 04 '11 at 21:18

1 Answers1

45

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.

Alinium
  • 1,481
  • 2
  • 17
  • 23