トラッキング コード

8/30/2012

Never be called Application#onTerminate()


I checked up that Application(not Activity) has module of handling "stopped / resumed".
There was no explicit modules that are called from the frameworks.


So, What is Application#onTerminate()? Where is called in frameworks?
Are described in the Android Developers.

http://developer.android.com/reference/android/app/Application.html#onTerminate()

This method is for use in emulated process environments. It will never be called on a production Android device, where processes are removed by simply killing them; no user code (including this callback) is executed when doing so.

This Module will be present for what?

I do "grep" in Android frameworks, it is called from ActivityThread.java.

                case EXIT_APPLICATION:
                    if (mInitialApplication != null) {
                        mInitialApplication.onTerminate();
                    }
                    Looper.myLooper().quit();
                    break;


When ActivityThread#scheduleExit() send message, this process is called.

2 module in ActivityManagerService.java is called ActivityThread#scheduleExit()。


private final boolean attachApplicationLocked(IApplicationThread thread, int pid)
final void trimApplications()

Cord in module.
                    if (app.pid > 0 && app.pid != MY_PID) {
                        EventLog.writeEvent(EventLogTags.AM_KILL, app.pid,
                                app.processName, app.setAdj, "empty");
                        Process.killProcessQuiet(app.pid);
                    } else {
                        try {
                            app.thread.scheduleExit();
                        } catch (Exception e) {
                            // Ignore exceptions.
                        }
                    }
If the following case to call ActivityThread#scheduleExit().
  • PID is under "0"
  • PID is MY_PID(= System Process)


When Application is same "System Process", called ActivityThread#scheduleExit().
So, It is not application of "same System Process"...