Advanced Android tricky problem of summary

One problem: Android neutron really can not update the UI thread it?

Reference answer:
the child access to the UI thread is created in the onCreate () method is an extreme case, the program does not crash. Since
ViewRootImpl has not been created, it can not detect whether the current thread to the UI thread.

  • ViewRootImpl created after the () callback method in onResume.
  • ViewRootImpl is created in WindowManagerGlobal of addView () method.

Question two: Android why the main thread will not Looper.loop () stuck in the cycle of death?

Reference answer:

  • Process: first create a process runs each app before, the process by Zygote fork out for carrying a variety Activity running on App / Service and other components. For the upper application process is completely transparent, which is google intentional, so that the program is run on App Android Runtime. In most cases an App runs in one process, unless configured Android in AndroidManifest.xml: process attributes, or by native code fork process.
  • Thread: Thread for applications is very common, such as each new Thread () start a new thread is created. The sharing of resources between threads and processes App where, from the perspective of Linux processes and threads in addition to whether to share resources, and there is no essential difference is a task_struct structure, nothing more than a piece of executable appears in the CPU process or thread code, CPU scheduling algorithm using CFS, to ensure that each task are as fair as possible to enjoy the time slice CPU.
  • For thread since it is a piece of executable code, executable code execution when completed, will be the termination of the life cycle of the thread, and the thread exits. As for the main thread, we never want to be running for some time, and that they quit, how to ensure that it has been able to survive it? Simple approach is executable code that could have been executed down, the cycle of death will not be able to ensure the exit, for example, binder thread is the method of infinite loop, loop through different ways and Binder drive to read and write, of course, not simply infinite loop, will sleep when there is no news. But here it may well lead to another problem, since it is the cycle of death and how to deal with other matters it? By creating a new thread. Really will get stuck in the main thread of operation is the callback method onCreate / onStart / onResume and other operations for too long will lead to dropped frames, even ANR occurs, looper.loop itself does not cause the application stuck.

Question three: the relationship Binder, IBinder, IInterface of

Reference answer:

  • Binder: conceptual meaning of Binder, and a BinderProxy associated objects;
  • IBinder: an interface, it implements Binder class is abstract Binder;
  • IInterface: an interface, AIDL interface must inherit it;
Published 225 original articles · won praise 64 · Views 200,000 +

Guess you like

Origin blog.csdn.net/duoduo_11011/article/details/103964961