簡體   English   中英

Android應用程序可以使用多少個廣播接收器?

[英]How many broadcast receiver can be used in Android application?

我正在處理一個同時處理電子郵件和聊天功能的項目。 對於聊天,我使用套接字,對於郵件功能,我使用Java Mail Api。 現在的問題是,“對於這兩種功能,我都需要一個廣播接收器,因此可以在一個應用程序中使用兩個廣播接收器。

這是代碼。

Android清單:-

<receiver android:name=".receivers.ChatMsgReceiver">
    <intent-filter android:priority="500">
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>

<receiver android:name=".receivers.EmailReceiver">
        <intent-filter android:priority="500">
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <action android:name="android.intent.action.QUICKBOOT_POWERON"/>
    </intent-filter>
</receiver>

電子郵件收件人類文件。

public class EmailReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    //My rest code goes here's

}
}

聊天接收器類文件。

public class ChatMsgReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    //My rest code goes here's

}
}

因此我可以在單個應用程序中使用兩個廣播接收器。

是的你可以。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM