在Android中,根据广播的执行顺序不同,将其分为有序广播和无序广播。无序广播是一种完全异步执行的广播,有序广播是同步执行的广播。
接下来通过一个拦截有序广播的案例让大家更深刻的认识有序广播。
实现界面如下:
1.创建程序
拦截有序广播对应的布局文件(activity_main.xml)如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="cn.edu.bzu.myapplication.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:onClick="send"