《第一行代码》学习笔记19-广播接收器Broadcast_Receiver(2)

1.解决广播的安全性问题,Android引入了一套本地广播机制,使用该机制发出的广播只能够在应用程序内部进行传递,并且广播接收器只能
接收来自本应用程序发出的广播。
2.本地广播无法通过静态注册来接收,因为静态注册就是为了让程序在未完全启动的情况下也能收到广播,而发送本地广播时,程序肯定已经
启动了,因此也完全不需要使用静态注册功能。
3.本地广播优势:
(1)可以明确知道正在发送的广播不会离开程序,不需要担心机密数据泄漏。
(2)其他程序无法将广播发送到程序内部,不需要担心会有安全漏洞的隐患。
(3)发送本地广播比发送系统全局广播将会更加高效。
4.强制下线功能:只需要在界面上弹出一个对话框,让用户无法进行任何其他操作,必须要点击对话框中的确定按钮,然后回到登陆界面。
5.编写登陆界面

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:stretchColumns="1"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TableRow>

        <TextView
            android:layout_height="wrap_content"
            android:text="Account:"/>

        <EditText
            android:id="@+id/account"
            android:layout_height="wrap_content"
            android:hint="Input your account"/>
    </TableRow>

    <TableRow>

        <TextView
            android:layout_height="wrap_content"
            android:text="Password:"/>

        <EditText
            android:id="@+id/password"
            android:layout_height="wrap_content"
            android:inputType="textPassword"/>
    </TableRow>

    <TableRow>

        <Button
            android:id="@+id/login"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="Login"/>
    </TableRow>

</TableLayout>
原文地址:https://www.cnblogs.com/Iamasoldier6/p/5020100.html