中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android 發(fā)送廣播簡(jiǎn)易工具類

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
    /** 
     * 發(fā)送廣播簡(jiǎn)易工具類 
     * Created by Liam on 2015/4/2. 
     */  
    public class BroadcastUtil {  
      
        /** 
         * 構(gòu)造函數(shù)設(shè)為private,防止外部實(shí)例化 
         */  
        private void BroadcastManager() {  
        }  
      
        /** 
         * 注冊(cè)廣播接收器 
         * 
         * @param ctx       Context(不可空) 
         * @param iReceiver IReceiver(不可空) 
         * @param action    Intent.Action(不可空) 
         */  
        public static void registerReceiver(Context ctx, final IReceiver iReceiver, final String action) {  
            if (ctx == null || iReceiver == null || action == null) throw new IllegalArgumentException("使用registerReceiver()注冊(cè)廣播時(shí),參數(shù)Context、IReceiver和Action不能為空!");  
      
            BroadcastReceiver receiver = new BroadcastReceiver() {  
                @Override  
                public void onReceive(Context context, Intent intent) {  
                    iReceiver.onReceive(context, intent);  
                }  
            };  
            IntentFilter filter = new IntentFilter(action);  
            ctx.registerReceiver(receiver, filter);  
        }  
      
        /** 
         * 發(fā)送廣播 
         * 
         * @param ctx    Context(不可空) 
         * @param i      Intent(可為null),不需要設(shè)置Action,請(qǐng)把Action作為參數(shù)傳入 
         * @param action Intent.Action(不可空) 
         */  
        public static void send(Context ctx, Intent i, final String action) {  
            if (ctx == null || action == null) throw new IllegalArgumentException("使用send()發(fā)送廣播時(shí),參數(shù)Context和Action不能為空!");  
      
            if (i == null) i = new Intent();  
            i.setAction(action);  
            ctx.sendBroadcast(i);  
        }  
      
      
        /** 
         * 接收廣播的頁(yè)面需要實(shí)現(xiàn),把接收后的操作覆寫在OnReceive()方法里 
         */  
        public interface IReceiver {  
            void onReceive(Context ctx, Intent intent);  
        }  
      
    }  

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:C#自定義字符串壓縮和解壓縮代碼庫(kù)

下一篇:C#折半插入排序算法