发送有序广播

1.布局界面


    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/stitch_one"
    tools:context="com.example.bz0209.myapplication.MainActivity">
            android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:layout_centerHorizontal="true"
        android:text="发送有序广播"
        android:textSize="20sp"
        android:background="#FBFBFF"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:onClick="send"
        />

2.运行界面

package com.example.bz0209.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void send(View view){
        Intent intent=new Intent();
        intent.setAction("Intercept_Stitch");
        sendOrderedBroadcast(intent,null);
    }
}

3.配置文件


    package="com.example.bz0209.myapplication">

            android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
       
           
               

               
           

       


                    android:name=".MyBroadcastReceiverOne"
            android:enabled="true"
            android:exported="true" >
           
               
           

       
                    android:name=".MyBroadcastReceiverTwo"
            android:enabled="true"
            android:exported="true" >
           
               
           

       
                    android:name=".MyBroadcastReceiverThree"
            android:enabled="true"
            android:exported="true">
           
               
           

       
   

4.添加广播接收者

package com.example.bz0209.myapplication;

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

public class MyBroadcastReceiverOne extends BroadcastReceiver {
    public MyBroadcastReceiverOne() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
        Log.i("MyBroadcastReceiverOne","自定义的广播接收者One,收到了广播事件");
    }
}


package com.example.bz0209.myapplication;

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

public class MyBroadcastReceiverTwo extends BroadcastReceiver {
    public MyBroadcastReceiverTwo() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
        Log.i("MyBroadcastReceiverTwo","自定义的广播接收者Two,收到了广播事件");
    }
}


package com.example.bz0209.myapplication;

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

public class MyBroadcastReceiverThree extends BroadcastReceiver {
    public MyBroadcastReceiverThree() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO: This method is called when the BroadcastReceiver is receiving
        // an Intent broadcast.
        Log.i("MyBroadcastReceiverThree","自定义的广播接收者Three,收到了广播事件");
    }
}发送有序广播_第1张图片发送有序广播_第2张图片


你可能感兴趣的:(发送有序广播)