zoukankan      html  css  js  c++  java
  • 广播

    一个发布广播的类

     public void buttonBroadcaseStatic(View view){
            Intent intent = new Intent();
            //创建一个广播的名字
            intent.setAction("SB");
            sendBroadcast(intent);
           

    一个接受广播的类

    package com.example.zhuopeng.demo1;
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;
    
    public class BroadcaseReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO: This method is called when the BroadcastReceiver is receiving
            // an Intent broadcast.
    //        throw new UnsupportedOperationException("Not yet implemented");
            Toast.makeText(context,"static BroadcaseReceiver is here ",Toast.LENGTH_SHORT).show();
            //截断广播
            //abortBroadcast();
        }
    }

    注册

    <receiver
                android:name=".BroadcaseReceiver"
                android:enabled="true"
                android:exported="true">
                <intent-filter android:priority="100"> <!-- 设置优先级,高优先级有权利截断广播 -->
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <action android:name="SB" />
                </intent-filter>
            </receiver>

  • 相关阅读:
    URL编码与解码
    什么通用数据交换格式更好
    JSON(JavaScript Object Notation)
    二维码与json都是数据交换格式
    数据的存在形式
    NSData、数据结构与数据转换
    物理结构与逻辑结构
    NSKeyedArchiver : NSCoder
    The Role of View Controllers
    Content-Type与MIME
  • 原文地址:https://www.cnblogs.com/da-peng/p/8439617.html
Copyright © 2011-2022 走看看