最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義廣播接收

 更新時(shí)間:2021年05月14日 13:53:35   作者:Lssの老父親  
這篇文章主要為大家詳細(xì)介紹了Android自定義廣播接收,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android自定義廣播接收的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)現(xiàn)效果:

MainActivity.java代碼:

package com.henu.broadcastsample;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private MyBroadcastReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void send(View v) {
        //動(dòng)態(tài)注冊(cè)廣播接收
        receiver = new MyBroadcastReceiver();
        String action = "henurjxy";
        IntentFilter intentFilter=new IntentFilter(action);
        registerReceiver(receiver,intentFilter);
        Intent intend = new Intent("henurjxy");
        sendBroadcast(intend);
    }
//在頁面銷毀時(shí),注銷廣播接收者
    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(receiver);
    }
}

MyBroadcastReceiver.java代碼:

package com.henu.broadcastsample;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class MyBroadcastReceiver extends BroadcastReceiver {
public  MyBroadcastReceiver(){}
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context,"是我發(fā)出的廣播哦",Toast.LENGTH_SHORT).show();
    }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

屯留县| 胶南市| 永善县| 汝城县| 胶州市| 谷城县| 双流县| 上饶县| 武定县| 安福县| 南宁市| 原阳县| 临西县| 布尔津县| 临高县| 红安县| 汾阳市| 新密市| 上犹县| 宁波市| 宝兴县| 收藏| 平山县| 清新县| 昌都县| 丽水市| 登封市| 新沂市| 镇坪县| 昭通市| 巴马| 休宁县| 海门市| 新安县| 稷山县| 福海县| 漳浦县| 扎兰屯市| 柳林县| 和政县| 静宁县|