1. 程式人生 > >Android從啟動到程式執行整個過程的整理已經出現常見問題分析和概念闡述

Android從啟動到程式執行整個過程的整理已經出現常見問題分析和概念闡述

  1. Message next() {
  2. // Return here if the message loop has already quit and been disposed.
  3. // This can happen if the application tries to restart a looper after quit
  4. // which is not supported.
  5. final long ptr = mPtr;
  6. if (ptr == 0) {
  7. return null;
  8. }
  9. int pendingIdleHandlerCount = -1; // -1 only during first iteration
  10. int nextPollTimeoutMillis = 0;
  11. for (;;) {
  12. if (nextPollTimeoutMillis != 0) {
  13. Binder.flushPendingCommands();
  14. }
  15. nativePollOnce(ptr, nextPollTimeoutMillis);
  16. synchronized (this) {
  17. // Try to retrieve the next message. Return if found.
  18. final long now = SystemClock.uptimeMillis();
  19. Message prevMsg = null;
  20. Message msg = mMessages;
  21. if (msg != null && msg.target == null) {
  22. // Stalled by a barrier. Find the next asynchronous message in the queue.
  23. do {
  24. prevMsg = msg;
  25. msg = msg.next;
  26. } while (msg != null && !msg.isAsynchronous());
  27. }
  28. if (msg != null) {
  29. if (now < msg.when) {
  30. // Next message is not ready. Set a timeout to wake up when it is ready.
  31. nextPollTimeoutMillis = (int) Math.min(msg.when - now, Integer.MAX_VALUE);
  32. } else {
  33. // Got a message.
  34. mBlocked = false;
  35. if (prevMsg != null) {
  36. prevMsg.next = msg.next;
  37. } else {
  38. mMessages = msg.next;
  39. }
  40. msg.next = null;
  41. if (DEBUG) Log.v(TAG, "Returning message: " + msg);
  42. msg.markInUse();
  43. return msg;
  44. }
  45. } else {
  46. // No more messages.
  47. nextPollTimeoutMillis = -1;
  48. }
  49. // Process the quit message now that all pending messages have been handled.
  50. if (mQuitting) {
  51. dispose();
  52. return null;
  53. }
  54. // If first time idle, then get the number of idlers to run.
  55. // Idle handles only run if the queue is empty or if the first message
  56. // in the queue (possibly a barrier) is due to be handled in the future.
  57. if (pendingIdleHandlerCount < 0
  58. && (mMessages == null || now < mMessages.when)) {
  59. pendingIdleHandlerCount = mIdleHandlers.size();
  60. }
  61. if (pendingIdleHandlerCount <= 0) {
  62. // No idle handlers to run. Loop and wait some more.
  63. mBlocked = true;
  64. continue;
  65. }
  66. if (mPendingIdleHandlers == null) {
  67. mPendingIdleHandlers = new IdleHandler[Math.max(pendingIdleHandlerCount, 4)];
  68. }
  69. mPendingIdleHandlers = mIdleHandlers.toArray(mPendingIdleHandlers);
  70. }
  71. // Run the idle handlers.
  72. // We only ever reach this code block during the first iteration.
  73. for (int i = 0; i < pendingIdleHandlerCount; i++) {
  74. final IdleHandler idler = mPendingIdleHandlers[i];
  75. mPendingIdleHandlers[i] = null; // release the reference to the handler
  76. boolean keep = false;
  77. try {
  78. keep = idler.queueIdle();
  79. } catch (Throwable t) {
  80. Log.wtf(TAG, "IdleHandler threw exception", t);
  81. }
  82. if (!keep) {
  83. synchronized (this) {
  84. mIdleHandlers.remove(idler);
  85. }
  86. }
  87. }
  88. // Reset the idle handler count to 0 so we do not run them again.
  89. pendingIdleHandlerCount = 0;
  90. // While calling an idle handler, a new message could have been delivered
  91. // so go back and look again for a pending message without waiting.
  92. nextPollTimeoutMillis = 0;
  93. }
  94. }

相關推薦

Android啟動程式執行整個過程整理已經出現常見問題分析概念闡述

Message next() {// Return here if the message loop has already quit and been disposed.// This can happen if the application tries to restart a looper after

Android啟動白屏解析,帶你一步步分析解決問題

本文同步發表於我的微信公眾號,掃一掃文章底部的二維碼或在微信搜尋 郭霖 即可關注,每天都有文章更新。 寫在前面 記得在本月初,我發表了一篇文章叫《 Android Studio新功能解析,你真的瞭解Instant Run嗎?》,裡面詳細講解了

Wpf ViewModel中 ObservableCollection不支援排程程式執行緒以外的執行緒對其 SourceCollection 進行的更改

Wpf中ViewModel類裡面經常會需要用到ObservableCollection來管理列表資料,在做非同步通訊的時候也會碰到“不支援從排程程式執行緒以外的執行緒對其 SourceCollection 進行的更改”這樣的異常,解決方法如下 1 ThreadPool.

LIVE555學習3:live555MediaServer講解——Live555啟動到響應Client過程分析

文章目錄 1 概述 2 程式碼分析 2.1 doEventLoop 2.2 計劃任務 2.3 RTSP服務 2.3.1 呼叫關係 2.3.2 Server監聽埠的建立 2.3.3 計劃任務

CVI程式執行時異常整理

Q:ActiveX controls cannot be created in a thread whose concurrency model is multithread apartment (MTA) A:The fix to this issue is to cal

Android之應用程式的安裝過程原始碼分析

Package管理服務PackageManagerService在安裝一個應用程式的過程中,會對這個應用程式的配置檔案AndroidManifest.xml進行解析,以便可以獲得它的安裝資訊。 Android系統中每一個應用程式都有一個Linux使用者ID,一個應用程式除了

hao—C++Java編譯到執行過程區別

以下內容純屬臆測,沒有科學依據,也不想(沒空)翻看權威資料。 一、C++編譯和執行過程 1、C++每個編譯單元整體上看都是各種宣告和定義     C++編譯單元就是指每個cpp檔案,整體上看(全域性的東西,函式內部不算,類定義內部不算)無非就是變數(包括類的例項也算變數

Android 零學資料結構與演算法(3)——HashMapLinkedHashMap

    本部落格的原創文章,都是本人平時學習所做的筆記,不做商業用途,如有侵犯您的智慧財產權和版權問題,請通知本人,本人會即時做出處理刪除文章。HashMap    基於雜湊表(散列表)的Map介面的實現,允許使用null鍵和null值,HashMap是非執行緒安全的,資料元

Mysql-Innodb : 一個位元組到整個資料庫表瞭解物理儲存結構邏輯儲存結構

首先要從Innodb怎麼看待磁碟物理空間說起      一塊原生的(Raw)物理磁碟,可以把他看成一個位元組一個位元組單元組成的物理儲存介質        如果要在這塊原生物理空間中插入一條記錄,不能單單隻插入資料,還需要插入一些管理記錄的資訊,這些管理資訊被稱為記錄頭,這裡假設是5位元

400錯誤引發的故障入手,談談如何分析修復常見的Nginx異常

作者介紹 林偉壕,網路安全DevOps新司機,先後在中國電信和網易遊戲從事資料網路、網路安全和遊戲運維工作。對Linux運維、虛擬化和網路安全防護等研究頗多,目前專注於網路安全自動化檢測、防禦系統構建。 眾所周知,Nginx是目前最流行的Web Server之一,也廣泛應用於負載均衡、反向代理等服

Android 程式啟動startActivity到生命週期變化的過程

在上篇文章中,我們瞭解了Android應用程式是如何啟動的,也介紹了具體的流程呼叫。知道了整個APP的啟動過程都是由ActivityThread類中執行的,而且啟動中的生命週期的變化都是通過Handler訊息機制來完成的。那麼這篇將要具體介紹從啟動到startA

Android啟動程式執行

Android從啟動到程式執行整個過程的整理 1Android是基於Linux的一個作業系統,它可以分為五層,下面是它的層次架構圖,可以記一下,因為後面應該會總結到SystemServer這些Application Framework層的東西 Android的五層架構從上到下依次是:應

正在執行android程式,按home鍵之後退回到桌面,再次點選桌面圖示避免再次重新啟動程式的終極解決辦法

在網上找了好多方法,有的說 在AndroidManifest.xml中修改,MainActivity的launchMode,去掉android:launchMode="singleTask"啟動模式即可。 AndroidManifest.xml的配置程式碼 可是我的程式碼就是這樣

當一個類被載入後,它的靜態變數生命週期是什麼,是整個應用程式執行結束(比如java web程式類載入到伺服器關閉還是該執行執行完畢)還是別的什麼?

靜態變數在記憶體中只有一個,JAVA虛擬機器載入類的時候為其分配記憶體,位於方法區,被類的所有例項共享,其生命週期取決於類的生命週期。。。當類被解除安裝。。。靜態變數也被銷燬 取決於類載入器。如果換了一個類載入器,這個

Linux載入啟動執行程式過程(二)直譯器完成動態連結

接著上一篇部落格。前面的工作都是在核心完成的,接下來會回到使用者空間。第一步,直譯器(也可以叫動態連結器)首先檢查可執行程式所依賴的共享庫,並在需要的時候對其進行載入。ELF 檔案有一個特別的節區: .dynamic,它存放了和動態連結相關的很多資訊,例如動態連結器通過它找到

Android 取得應用程式啟動次數執行時間等資訊

使用情景:最近有個需求是統計後臺應用執行時間,如果一個應用在後臺執行超過一定時間就Kill掉程序,達到省電的目的。此時就可以使用PkgUsageStats這個類來實現啦!通過com.android.internal.os.PkgUsageStats這個類可以得到一個應用

Android程式包管理(2)--使用adb install執行安裝過程

二、程式安裝過程 1.使用adb install執行安裝過程 使用adb install執行安裝過程整體流程圖如下: 一、使用adb install命令安裝apk 1.adb指令對應原始檔system/core/adb/commandline.c

java --代碼編譯執行整個過程

pan home 面向 share 簡單的 下一條 c++ oot 註解 1. 什麽是 JVM   JVM 是 Java 的核心和基礎,在 Java 編譯器和 os 平臺之間的虛擬處理器。它是一種基於下層的操作系統和硬件平臺並利用軟件方法來實現的抽象的計算機,可以在上面執行

Android系統啟動流程(一)解析init進程啟動過程

option 寫入 android change failed miss 通知 target sna 前言 作為“Android框架層”這個大系列中的第一個系列,我們首先要了解的是Android系統啟動流程,在這個流程中會涉及到很多重要的知識點,這個系列我們就來一一講解它們

匯編語言——匯編程序寫出到最終執行過程

生成 語言 樣式 art masm 程序編譯 spa color assume 一個匯編語言程序從寫出到最終執行的簡要過程: 編寫--〉編譯--〉連接--〉執行 1、編寫 notepad++選擇Assembly編寫程序,保存成xx.asm,樣式如下 assume c