Android 面试之 Android 篇二_澳门正规博彩十大网站排名

您当前的位置:主页 > 澳门正规博彩十大网站 >

Android 面试之 Android 篇二

发布时间:2018-11-29 15:44编辑:[db:作者]阅读(

      本文出产己 Eddy Wiki ,转载请注皓出产处:http://eddy.wiki/interview-android.html

      本文收集儿子整顿理了 Android 面试中会遇到与 Android 知趣关的信述题。

      第壹种:Handler+Message

      第二种:

      第叁种:

      禀接 Thread 类

      完成 Runnable 接口

      HandlerThread

      Handler

      AsyncTask

      Activity.runOnUiThread(Runnable)

      View.post(Runnable),View.postDelay(Runnable,long)

      Service

      Thread

      IntentService

      AsyncTask

      When to use ?

      Task with no UI, but shouldn't be too long. Use threads within service for long tasks.

      - Long task in general.- For tasks in parallel use Multiple threads (traditional mechanisms)

      - Long task usually with no communication to main thread.(Update)- If communication is required, can use main thread handler or broadcast intents- When callbacks are needed (Intent triggered tasks).

      - Small task having to communicate with main thread.- For tasks in parallel use multiple instances OR Executor

      Trigger

      Call to methodonStartService()

      Thread start() method

      Intent

      Call to method execute()

      Triggered From (thread)

      Any thread

      Any Thread

      Main Thread (Intent is received on main thread and then worker thread is spawed)

      Main Thread

      Runs On (thread)

      Main Thread

      Its own thread

      Separate worker thread

      Worker thread. However, Main thread methods may be invoked in between to publish progress.

      Limitations /****Drawbacks

      May block main thread

      - Manual thread management- Code may become difficult to read

      - Cannot run tasks in parallel.- Multiple intents are queued on the same worker thread.

      - one instance can only be executed once (hence cannot run in a loop) - Must be created and executed from the Main thread

      运用 synchronized 关键字创立 synchronized 方法。

      运用 synchronized 创立同步代码块。

      参考:

      http://www.itzhai.com/java-based-notebook-thread-synchronization-problem-solving-synchronization-problems-synchronized-block-synchronized-methods.html#2.1%E3%80%81%E4%BD%BF%E7%94%A8synchronized%E5%85%B3%E9%94%AE%E5%AD%97%E5%88%9B%E5%BB%BAsynchronized%E6%96%B9%E6%B3%95%EF%BC%9A

      http://www.juwends.com/tech/android/android-inter-thread-comm.html

      前台经过:即与用户正提交互的Activity容许Activity用到的Service等,假设体系内存放缺乏时前台经过是最末被杀死的

      却见经过:却以是处于暂停样儿子(onPause)的Activity容许绑定在其上的Service,即被用户却见,但鉴于违反掉落了焦点而不能与用户提交互

澳门正规博彩十大网站排名