Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
您现在的位置: Android教程網 >> Android系統教程 >  >> Android 技術 >> Android 開發 >> 初階開發

Android Context 到底是什麼?

編輯:初階開發

Context 是 Android 中非常重要的抽象概念,可理解為應用程式與系統資源溝通的上下文環境。它位於 android.content.Context,許多 API 都需要 Context 才能正確執行。

常見的 Context 實作包括 Activity、Service 與 BroadcastReceiver。在 Activity 中可直接使用 this,但在匿名內部類或按鈕事件監聽器中,可能需要使用 ActivityName.this 才能取得正確的 Context。

像是 Toast、getSystemService、openFileInput 等方法,通常都需要 Context 來辨識呼叫來源。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved