導航:首頁 > 操作系統 > android有序廣播優先順序

android有序廣播優先順序

發布時間:2022-06-24 02:43:17

① 12、注冊廣播有幾種方式,這些方式有何優缺點請談談android引入廣播機制的用意。

  1. 注冊廣播的分類:靜態注冊和動態注冊。

    靜態注冊:在清單文件里直接注冊,從app開啟到app銷毀,一直在接收廣播,接收廣播時間長,但是接收廣播的優先順序低於動態注冊廣播。

    動態注冊:動態注冊,動態銷毀,從onCreate到取消注冊,期間接收廣播,接收廣播時間是短且可控,接收廣播的優先順序高。例如:

    發送廣播:
    Intent i = new Intent();
    i.setAction("ACTION_CLOSE");
    sendBroadcast(i);

    接受廣播:
    onCreate(){

    //注冊廣播的接受者
    IntentFilter filter = new IntentFilter();
    filter.addAction("ACTION_CLOSE_ACTIVITY");
    receiver = new InnerReceiver();
    registerReceiver(receiver, filter);
    }

    private class InnerReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
    //TODO 當前Activity接收到廣播 需要做的事情
    }
    }
    }

    //注銷廣播

    @Override
    protected void onDestroy() {
    super.onDestroy();
    unregisterReceiver(receiver);
    }


2.引入廣播的原因:

a) 不同的app之間傳信通用

b)發出一條指定,需要多個Activity都需要有反應


注意:以上僅供參考,如有疑問,請追問,謝謝。

② android 優先順序對無序廣播生效

同一優先順序的廣播接收器,動態的要比靜態注冊的早。
動態注冊:即由代碼注冊的廣播接收器靜態注冊:即在 AndroidManifest.xml 中注冊的廣播接收器 優先順序: 當廣播為有序發送的時候,要按這個排序並順序發送。 sendBroadcast 發送的是無序廣播。sendOrderedBroadcast 發送的是有序廣播。 好了,現在尋找問題原因,在找原因前肯定有這樣的想法,一個有序隊列,既然允許有相同的優先順序存在,那麼在同優先順序內要不然有排序子因素,要不基就是按照某種操作可能影響順序。後者可能性很大。 打開源碼,順著 動態注冊廣播接受器 找,最後是 ActivityManagerService.java 這個文件找到了 registerReceiver 的實現。同地也看到,存儲的廣播接收器列表是 HashMap mRegisteredReceivers 這個變理。 裡面有一段代碼為: ReceiverList rl = (ReceiverList)mRegisteredReceivers.get(receiver.asBinder()); if (rl == null) { rl = new ReceiverList(this, callerApp, Binder.getCallingPid(), Binder.getCallingUid(), receiver); if (rl.app != null) { rl.app.receivers.add(rl); } else { try { receiver.asBinder().linkToDeath(rl, 0); } catch (RemoteException e) { return sticky; } rl.linkedToDeath = true; } mRegisteredReceivers.put(receiver.asBinder(), rl); } 在裡面查找有沒有這個 Receiver , 如果沒有 put 進去。 看到這里貌似沒有對廣播的順序做處理。是不是有別的地方做排序呢,找找成員變理,發現一個可疑的變數:final ArrayList mOrderedBroadcasts沒錯,感覺就應該是它了。 找找對它的操作,只有一處 mOrderedBroadcasts.set ,把代碼摘錄一下: BroadcastRecord r = new BroadcastRecord(intent, callerApp,
callerPackage, callingPid, callingUid, requiredPermission,
sticky, false); mOrderedBroadcasts.set(i, r);在這里放入了一個 BroadcastRecord 對像,而這個對像中主要的東西其實是 receivers向上跟蹤 int NT = receivers != null ? receivers.size() : 0; int it = 0; ResolveInfo curt = null; BroadcastFilter curr = null; while (it < NT && ir < NR) { if (curt == null) { curt = (ResolveInfo)receivers.get(it); } if (curr == null) { curr = registeredReceivers.get(ir); } if (curr.getPriority() >= curt.priority) { // Insert this broadcast record into the final list. receivers.add(it, curr); ir++; curr = null; it++; NT++; } else { // Skip to the next ResolveInfo in the final list. it++; curt = null; } } 發現了一段 對 receivers 排序的代碼,並且判斷也是 priority 的值,用的是 >= 方式 感覺的找到了地方,但是對 Activity Manager Service 這個模塊卻更加的不懂了,以後有機會一定要分析一下這塊是怎樣設計的,才能確定本文的問題所在。暫時記錄,以後分析!

③ Android靜態注冊廣播和動態注冊廣播的區別

1.動態注冊廣播不是常駐型廣播,也就是說廣播跟隨activity的生命周期。注意: 在activity結束前,移除廣播接收器。
靜態注冊是常駐型,也就是說當應用程序關閉後,如果有信息廣播來,程序也會被系統調用自動運行。
它的生命周期為從回調onReceive()方法開始到該方法返回結果後結束。
2.當廣播為有序廣播時:
1 優先順序高的先接收
2 同優先順序的廣播接收器,動態優先於靜態
3 同優先順序的同類廣播接收器,靜態:先掃描的優先於後掃描的,動態:先注冊的優先於後注冊的。

④ android有序廣播和無序廣播的區別

BroadcastReceiver所對應的廣播分兩類:普通廣播和有序廣播。
普通廣播:通過Context.sendBroadcast()方法來發送,它是完全非同步的。
所有的receivers(接收器)的執行順序不確定,因此所有的receivers(接收器)接收broadcast的順序不確定。
這種方式效率更高,但是BroadcastReceiver無法使用setResult系列、getResult系列及abort(中止)系列API

有序廣播:是通過Context.sendOrderedBroadcast來發送,所有的receiver依次執行。
BroadcastReceiver可以使用setResult系列函數來結果傳給下一個BroadcastReceiver,通過getResult系列函數來取得上個BroadcastReceiver返回的結果,並可以abort系列函數來讓系統丟棄該廣播,使用該廣播不再傳送到別的BroadcastReceiver。
可以通過在intent-filter中設置android:priority屬性來設置receiver的優先順序,優先順序相同的receiver其執行順序不確定。
如果BroadcastReceiver是代碼中注冊的話,且其intent-filter擁有相同android:priority屬性的話,先注冊的將先收到廣播。

有序廣播,即從優先順序別最高的廣播接收器開始接收,接收完了如果沒有丟棄,就下傳給下一個次高優先順序別的廣播接收器進行處理,依次類推,直到最後。如果多個應用程序設置的優先順序別相同,則誰先注冊的廣播,誰就可以優先接收到廣播。
這里接收簡訊的廣播是有序廣播,因此可以設置你自己的廣播接收器的級別高於系統原來的級別,就可以攔截簡訊,並且不存收件箱,也不會有來信提示音。
實現方法是:
<receiver Android:name=".SmsReceiver">

<intent-filter android:priority="100">

<action android:name="android.provider.Telephony.SMS_RECEIVED"/>

</intent-filter>

</receiver>
裡面的android:priority="100"就是設定廣播接收器的級別,這個值從1000~-1000,數值越大,優先順序別就越高。
希望幫助到你~~感謝採納

⑤ 怎麼確定android系統廣播是否有序

可以試下:Bundle bundle = getResultExtras(true)),看能拿到數據不,能拿到,證明是有序廣播,拿不到是普通廣播。
對於有序廣播,前面的接收者可以將數據通過setResultExtras(Bundle)方法存放進結果對象,然後傳給下一個接收者。但有可能前面沒有存,那就不好判斷了。

⑥ 安卓broadcastreceiver怎麼接收的廣播

1.廣播接收者(BroadcastReceiver)

廣播接收者(BroadcastReceiver)繼承BroadcastReceiver類接收廣播意圖的Java類,重寫:
public void onReceive(Context context,Intent intent),其中intent可以獲得傳遞的數據;
廣播意圖就是通過Context.sendBroadcast(Intent intent)或Context.sendOrderedBroadcast(Intentintent)發送的意圖,通過這個語句,能夠廣播給所有滿足條件的組件,比如intent設置了action="Receiver",則所有在AndroidManifest.xml中設置過<actionandroid:name="Receiver"/>的廣播接收者都能夠接收到廣播;

2.廣播發送者sendBroadcast()

通常廣播發送方就是調用Context.sendBroadcast()的程序,通常廣播發送方都是通過隱式意圖發送出去;

廣播發送方分為普通廣播和有序廣播;
同步廣播:發送方發出後,幾乎同時到達多個廣播接收者處,某個接收者不能接收到廣播後進行一番處理後傳給下一個接收者,並且無法終止廣播繼續傳播;Context.sendBroadcast(intent);
有序廣播:廣播接收者需要提前設置優先順序,優先順序高的先接收到廣播,優先順序數值為-1000~1000,在AndroidManifest.xml的<intent-filterandroid:priority="1">設置;比如存在3個廣播接收者A、B、C、D,優先順序A>B>C>D,因此A最先收到廣播,當A收到廣播後,可以向廣播中添加一些數據給下一個接收者(intent.putExtra()),或者終止廣播 abortBroadcast();Context.sendOrderedBroadcast(intent);

一、同步廣播發送方核心代碼
Intent intent = new Intent();
intent.setAction("Receiver");
Context.sendBroadcast(intent);

有序廣播發送方核心代碼:
Intent intent = new Intent();
intent.setAction("Receiver");
Context.sendOrderedBroadcast(intent,null);

二、廣播接收者核心代碼:
public class MyReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent)
{
Bundle bundle = intent.getExtras();...
}
}

三 注冊該廣播
AndroidManifest.xml 注冊方式
<receiver android:name=".MyReceiver">
<intent-filter android:priority="1000">
<action android:name="Receiver"/>
</intent-filter>
</receiver>

Java類注冊方式
publicvoid registerBoradcastReceiver()
{
IntentFilter myIntentFilter = new IntentFilter();
myIntentFilter.addAction("Receiver");
registerReceiver(廣播類對象, myIntentFilter);
}

簡單例子

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
public class Test extends Activity{
private final String ACTION_NAME = "Receiver";
private Button mBtnEvent = null;

protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//注冊廣播
registerBoradcastReceiver();
LinearLayout mLinearLayout = new LinearLayout(this);
mBtnEvent= new Button(this);
mBtnEvent.setText("發送廣播");
mLinearLayout.addView(mBtnMsgEvent);

setContentView(mLinearLayout);

mBtnEvent.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sendTestBroadcast();

}
});
}
//發送廣播
private void sendTestBroadcast()
{
Intent mIntent = new Intent(ACTION_NAME);
mIntent.putExtra("strData", "發送廣播,在這里傳送數據");
sendBroadcast(mIntent);
}
private BroadcastReceiver myReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(ACTION_NAME)){
Toast.makeText(Test.this, "接收測試", 200);
}
}
};
//注冊廣播
public void registerBoradcastReceiver(){
IntentFilter myIntentFilter = new IntentFilter();
myIntentFilter.addAction(ACTION_NAME);
registerReceiver(myReceiver, myIntentFilter);
}
}

⑦ android 如何自定義常駐廣播

Android廣播機制指的是,在一個應用程序運行的時候可以自定義一個消息類型,讓相應的接收器去處理這個消息或者是系統消息,比如來電話了、來簡訊了、手機沒電了等等系統發送的消息。系統發送的消息也可以通過廣播的方式通知給應用程序,這樣子就避免了新開一個Thread去監聽系統或其他應用發送過來的消息的狀態。

Android廣播的分類:
1、 普通廣播:這種廣播可以依次傳遞給各個處理器去處理
2、 有序廣播:這種廣播在處理器端的處理順序是按照處理器的不同優先順序來區分的,高優先順序的處理器會優先截獲這個消息,並且可以將這個消息刪除
3、 粘性消息:粘性消息在發送後就一直存在於系統的消息容器裡面,等待對應的處理器去處理,如果暫時沒有處理器處理這個消息則一直在消息容器裡面處於等待狀態。
注意:普通廣播和粘性消息不同被截獲,而有序廣播是可以被截獲的

處理器的注冊:
1、 在代碼中用函數代碼動態的方式注冊。動態注冊的處理器必須用代碼動態的銷毀,每次用來處理消息的就一個實例對象
2、 在配置文件裡面靜態注冊,靜態注冊有個特點,那就是一旦注冊就會一直存在於系統裡面,無論應用是否關閉或開關機。(簡直就是一個流氓軟體病毒啊~)。靜態注冊每次有處理消息就由系統new一個處理器處理,並銷毀
下面具體看看Android廣播消息的發送、注冊、處理過程:
① 自定義處理器類:

public class MyBroadcastReceiver4 extends BroadcastReceiver {
public MyBroadcastReceiver4() {
System.out.println("創建了一個由registerReceiver()注冊的廣播接收器");
}

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
System.out.println("MyBroadcastReceiver4收到了一個" + action + "消息");
if (isOrderedBroadcast()) {
System.out.println("這是一個有序廣播,已經被攔截了。");
this.abortBroadcast();
} else {
System.out.println("這不是一個有序廣播");
}

Bundle bundle = intent.getExtras();
if (bundle != null) {
System.out.println("該消息攜帶的數據如下:");
// 獲得bundle的一個key的集合
Set set = bundle.keySet();
// 獲得上述集合的迭代器
Iterator iterator = set.iterator();
// 用迭代器遍歷集合
while (iterator.hasNext()) {
// 取得集合中的一個內容
String str = (String) iterator.next();
// 取得Bundle中的內容
System.out.println(str + "--->" + bundle.get(str));
}
} else {
System.out.println("該消息沒有攜帶數據");
}

Toast toast = Toast.makeText(context, "MyBroadcastReceiver4收到了一個"
+ action + "消息", Toast.LENGTH_LONG);
toast.show();
//將這個消息截獲(從消息容器移除)這樣其他處理器就沒法接收到這個消息
this.abortBroadcast();
}
}

② 發送廣播消息

⑴、 發送普通廣播:
// 發送一個普通消息
Intent intent = new Intent(); intent.setAction("asdfasdf");
Android_09_10Activity.this.sendBroadcast(intent);

⑵、 發送有序廣播:
// 發送一個有序消息
Intent intent = new Intent();
intent.setAction("asdfasdf"); Android_09_10Activity.this.sendOrderedBroadcast(intent,
null);
⑶、 發送粘性廣播:
// 發送一個粘性消息
Intent intent = new Intent();
intent.setAction("qwerqwer"); Android_09_10Activity.this.sendStickyBroadcast(intent);
③ 注冊廣播接收器
⑴動態注冊:
// 注冊一個廣播接收器
IntentFilter intentFilter = new IntentFilter("asdfasdf");
intentFilter.setPriority(0);
Android_09_10Activity.this.registerReceiver(mbr2,
intentFilter);
⑵靜態注冊:

<receiver android:name=".MyBroadcastReceiver4" >

<intent-filter android:priority="1000" >

<action android:name="android.intent.action.WALLPAPER_CHANGED" />

<action android:name="android.provider.Telephony.SMS_RECEIVED" />

<action android:name="android.intent.action.PHONE_STATE" />

<action android:name="android.intent.action.PACKAGE_REMOVED" />

//這一句比較特殊,是上面那個廣播消息特有的

<data android:scheme="package" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

想發送粘性消息的時候必須在配置文件裡面獲取許可權:
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

想用自定義處理器對系統廣播進行處理的話也必須在注冊文件裡面申明獲取許可權,比如:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

⑧ android開發音樂優先順序問題(當鬧鍾、鈴聲、音樂三者同時發生時如何優先順序處理)

發出有序廣播 : 鬧鍾來了,鈴聲來了,音樂來了,

然後就如果有注冊相關receiver的廣播就啟動了,

這些代碼是系統級別的代碼,你是具體要哪塊的?

⑨ android:priority優先順序相同,包名次序怎麼排序

A PriorityQueue holds elements on a priority heap, which orders the elements according to their natural order or according to the comparator specified at construction time. If the queue uses natural ordering, only elements that are comparable are permitted to be inserted into the queue.

The least element of the specified ordering is stored at the head of the queue and the greatest element is stored at the tail of the queue.

A PriorityQueue is not synchronized. If multiple threads will have to access it concurrently, use the PriorityBlockingQueue.

⑩ 為什麼Android要使用各種BroadcastReceiver

作為Android四大組件之一的BroadcastReceiver(廣播接收者),同Activity(活動)一樣,經常被大家用到,網上也是一堆對它的講解,那麼為什麼Android要用廣播接收者這種機制呢?
廣播分為:普通廣播和有序廣播
1.Normal broadcasts(普通廣播):Normal broadcasts是完全非同步的可以同一時間被所有的接收者接收到。消息的傳遞效率比較高。但缺點是接收者不能將接收的消息的處理信息傳遞給下一個接收者也不能停止消息的傳播。可以利用Context.sendBroadcast發送。
2.Ordered broadcasts(有序廣播):Ordered broadcasts的接收者按照一定的優先順序進行消息的接收。一次傳送到一個接收器。 隨著每個接收器依次執行,它可以將結果傳播到下一個接收器,或者它可以完全中止廣播,使得它不會被傳遞到其他接收器。 命令接收器運行可以用匹配的意圖過濾器的android:priority屬性控制; 具有相同優先順序的接收器將以任意順序運行。可以利用Context.sendOrderedBroadcast發送。
官網上介紹廣播是用的監聽系統網路狀況的例子,其實關鍵字在於「監聽」。
(1) 創建廣播接收者
BroadcastReceiver是一個抽象類,所以我們要創建自己的廣播接收者就要繼承它,繼承後會有提示重寫onReceive方法。
public class NetworkBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isAvailable()) {
Toast.makeText(context, "有網路連接", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "無網路連接", Toast.LENGTH_SHORT).show();
}
}
}
}

廣播接收者的生命周期是從接收廣播開始,到onRecevier方法執行完成結束,時間很短,一般不允許處理大批量耗時操作。這里順便給出列印NetworkInfo的信息以供參考:
NetworkInfo:
type: WIFI[,type_ext: WIFI],
state: CONNECTED/CONNECTED,
reason: (unspecified),
extra: "TP-LINK_EFE8",
roaming: false,
failover: false,
isAvailable: true,
: false,
isIpv4Connected: true,
isIpv6Connected: false

[type: MOBILE[LTE],
state: CONNECTED/CONNECTED,
reason: connected,
extra: cmnet,
roaming: false,
failover: false,
isAvailable: true,
: false]

(2) 靜態注冊廣播
靜態注冊廣播,需要在AndroidManifest.xml中,添加<recevier/> 標簽,將廣播接收者注冊到應用中。要添加過濾器IntentFilter,由於系統網路變化時會發送ConnectivityManager.CONNECTIVITY_ACTION ("android.net.conn.CONNECTIVITY_CHANGE")的廣播,所以我們要監聽這條廣播。
<receiver android:name=".NetworkBroadcastReceiver">
<intent-filter android:priority="1000">
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>

這里priority代表的是執行順序的優先順序,取值[-1000,1000],後面的有序廣播會講到。
(3) 動態注冊廣播
i.意圖過濾器 IntentFilter 用於給BroadcastReceiver綁定監聽廣播類型
ii.自定義的BroadcastReceiver,例如上文的
iii.注冊方法 Context.registerReceiver(Receiver, IntentFilter)
iv.反注冊方法 unregisterReceiver(Receiver)
IntentFilter mFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
mReceiver = new ();
registerReceiver(mReceiver, mFilter);

@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(mReceiver);
}

這段代碼是成對出現的,可以在onCreate的時候注冊,在onDestroy的時候反注冊,也可以在onResume和onPause中執行這寫方法。不過Google API推薦的做法,在activity的onResume()中注冊,在onPause()反注冊。效果是當界面pause時,就不接收廣播,從而減少不必要的系統開銷。還有就是一定要主動反注冊你的廣播,否則會出現異常。
動態注冊和靜態注冊的差別:動態注冊後,廣播接收者會依賴Activity的生命周期,而靜態注冊的廣播不會,只要是系統有發出的廣播,它都會接收,與程序是否啟動無關。
(4) 發送普通廣播
具體使用的方法是sendBroadcast(Intent intent),通過隱式調用就可以,注意action是你自定義的,意思就是不可以發送系統廣播,我試了,直接就崩了。
Intent intent = new Intent();
intent.setAction("com.fleming.chen.mybroadcast");
sendBroadcast(intent);

針對(3)(4)兩點,如果你要用到的廣播僅僅是應用里的,那麼你可以用LocalBroadcastManager這個類,它與上述描述中的區別在於:
LocalBroadcastManager.getInstance(context).registerReceiver(mReceiver, mFilter);

LocalBroadcastManager.getInstance(context).unregisterReceiver(mReceiver);

LocalBroadcastManager.getInstance(context).sendBroadcast(intent);

通過sendBroadcast發送的廣播,不會被通過LocalBroadcastManager類注冊的廣播接收者接收,反之也是如此,兩者是不可以」互通友誼「的,推薦使用LocalBroadcastManager來管理廣播。
(5) 發送有序廣播
上面講了那麼多都是普通廣播,那什麼又是有序廣播呢?
有序廣播關鍵在於這類廣播是有序的,上文中提到priority,這是IntentFilter的屬性,用來讓不同的廣播擁有不同的執行順序,即優先順序不同。
定義三種不同優先順序的廣播接收者:
public class MyBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.fleming.chen.myreceiver")) {
String message = getResultData();
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
setResultData("這是修改後的數據");//第一個接收後處理一下,再交給下一個
}
}
}

public class MyBroadcastReceiver2 extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.fleming.chen.myreceiver")) {
String message = getResultData();//得到上一個的處理結果
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
abortBroadcast();//主動停止廣播,不再繼續傳下去
}
}
}

public class MyBroadcastReceiver3 extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.fleming.chen.myreceiver")) {
//此時雖然該廣播接收者也監聽了,不過也沒有內容
Toast.makeText(context, getResultData(), Toast.LENGTH_SHORT).show();
}
}
}

<receiver android:name=".MyBroadcastReceiver" >
<intent-filter android:priority="1000">
<action android:name="com.fleming.chen.myreceiver"/>
</intent-filter>
</receiver>
<receiver android:name=".MyBroadcastReceiver2">
<intent-filter android:priority="0">
<action android:name="com.fleming.chen.myreceiver"/>
</intent-filter>
</receiver>
<receiver android:name=".MyBroadcastReceiver3">
<intent-filter android:priority="-1000">
<action android:name="com.fleming.chen.myreceiver"/>
</intent-filter>
</receiver>

Intent intent = new Intent();
intent.setAction("com.fleming.chen.myreceiver");
sendOrderedBroadcast(intent, null, null, null, 0, "這是初始的數據", null);

對於廣播的內容,在Android 7.0上做了修改,即Project Svelte:後台優化
Android 7.0 移除了三項隱式廣播,以幫助優化內存使用和電量消耗。此項變更很有必要,因為隱式廣播會在後台頻繁啟動已注冊偵聽這些廣播的應用。刪除這些廣播可以顯著提升設備性能和用戶體驗。
移動設備會經歷頻繁的連接變更,例如在 WLAN 和移動數據之間切換時。目前,可以通過在應用清單中注冊一個接收器來偵聽隱式 CONNECTIVITY_ACTION 廣播,讓應用能夠監控這些變更。由於很多應用會注冊接收此廣播,因此單次網路切換即會導致所有應用被喚醒並同時處理此廣播。
同理,在之前版本的 Android 中,應用可以注冊接收來自其他應用(例如相機)的隱式 ACTION_NEW_PICTURE 和 ACTION_NEW_VIDEO 廣播。當用戶使用相機應用拍攝照片時,這些應用即會被喚醒以處理廣播。
為緩解這些問題,Android 7.0 應用了以下優化措施:
面向 Android 7.0 開發的應用不會收到 CONNECTIVITY_ACTION 廣播,即使它們已有清單條目來請求接受這些事件的通知。在前台運行的應用如果使用 BroadcastReceiver 請求接收通知,則仍可以在主線程中偵聽 CONNECTIVITY_CHANGE。
應用無法發送或接收 ACTION_NEW_PICTURE 或 ACTION_NEW_VIDEO 廣播。此項優化會影響所有應用,而不僅僅是面向 Android 7.0 的應用。
如果您的應用使用任何 intent,您仍需要盡快移除它們的依賴關系,以正確適配 Android 7.0 設備。Android 框架提供多個解決方案來緩解對這些隱式廣播的需求。例如,JobScheler API 提供了一個穩健可靠的機制來安排滿足指定條件(例如連入無限流量網路)時所執行的網路操作。您甚至可以使用 JobScheler 來適應內容提供程序變化。
所以說,在Android的世界,到處都充滿著廣播,就是為了用來監聽手機的各種狀態,給用戶提醒,這是一種很好的用戶體驗,不過任何事情都是如此,廣播也不可以多用哦,

閱讀全文

與android有序廣播優先順序相關的資料

熱點內容
sdk命令 瀏覽:94
好玩免費下載的解壓游戲 瀏覽:9
單片機老師招聘考試內容 瀏覽:425
彈性雲伺服器配置流程 瀏覽:304
android交叉編譯linux 瀏覽:988
金聖嘆水滸傳pdf 瀏覽:501
安卓官換新機是什麼意思啊 瀏覽:922
java如何分頁 瀏覽:558
如何查找加密的視頻 瀏覽:742
單片機lcd漢字顯示 瀏覽:879
能夠識別中文的編譯器 瀏覽:63
androidlayout注釋 瀏覽:959
重啟手機命令 瀏覽:838
程序員那麼可愛男女主是誰 瀏覽:492
文件如何上傳到自己的伺服器 瀏覽:401
你用什麼app 瀏覽:224
安卓平板用什麼優化軟體 瀏覽:747
centos重新編譯程序 瀏覽:335
cocoapods命令 瀏覽:906
androidusb卸載 瀏覽:143