1.Android基本知識點

來源:互聯網
上載者:User

標籤:定義   ini   ssi   發送   not   許可權   依次   事件   move   

1、四大組件是什麼與它們的生命週期(及Fragment)。

  Activity: 通過Intent來進行通訊,intent中包含動作和動作的資料 

  BroadcastReceive:可以在廣播中啟動一個Activity或者Service來響應接收到的資訊,或者用NotificationManager 來通知使用者,可以對外部資料進行過濾,只對感興趣的事件進行響應。

    普通廣播:Context.sendBoradCast(intent)

    有序廣播:Context.sendOrderBroadcast(intent,receiverPermission),receiverPermission決定廣播的層級,值在-1000到1000之間,值越大,發送的優先順序越高。接收的廣播可以通過intentfilter中的priority設定優先權。abortBroadcast()可以截斷廣播。

    非同步廣播:通過Context.sendStickyBroadcast(intent)發送。還有sendStickyOrderedBroadcast(intent, resultReceiver, scheduler,  initialCode, initialData, initialExtras)方法,該方法具有有序廣播的特性也有非同步廣播的特性;發送非同步廣播要: <uses-permission android:name="android.permission.BROADCAST_STICKY" />許可權,接收並處理完Intent後,廣播依然存在,直到你調用removeStickyBroadcast(intent)主動把它去掉。

    監聽廣播Intent的步驟:1.定義一個類繼承BroadCastReceiver,然後重寫onReceive()方法。

              2.靜態註冊,直接在資訊清單檔中註冊或者動態註冊。代碼中registerReceiver(receive,intentfilter),登出unregisterReceiver(receive)。

    廣播的生命週期只有10s,如果做了耗時的操作,會導致ANR。

  Service:使用方法:1.繼承Service,資訊清單檔中註冊。通過startService()或者bindService()方法啟動。

通過startService()方法啟動的服務和調用者沒有關係,即使調用者關閉了,服務仍然運行想停止服務要調用Context.stopService(),此時系統會調用onDestory(),使用此方法啟動時,服務初次開機系統先調用服務的onCreate()-->onStart(),如果服務已經啟動再次調用只會觸發onStart()方法

使用bindService()啟動的服務與調用者綁定,只要調用者關閉服務就終止,使用此方法啟動時,服務初次開機系統先調用服務的onCreate()-->onBind(),如果服務已經啟動再次調用不會再觸發這2個方法,調用者退出時系統會調用服務的onUnbind()-->onDestory(),想主動解除綁定可使用Contex.unbindService(),系統依次調用onUnbind()-->onDestory();

  ContentProvider:其他應用可以通過ContentResolver類(見ContentProviderAccessApp例子)從該內容提供者中擷取或存入資料

1.Android基本知識點

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.