Android广播机制(一)

BroadcastReceiverActivity

package org.wp.activity;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class BroadcastReceiverActivity extends Activity {private Button sendButton;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);sendButton = (Button) this.findViewById(R.id.sendButton);sendButton.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();intent.setAction(Intent.ACTION_EDIT);BroadcastReceiverActivity.this.sendBroadcast(intent);}});}}

BroadcastReceiverTest

package org.wp.activity;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.util.Log;public class BroadcastReceiverTest extends BroadcastReceiver {private static final String TAG = "BroadcastReceiverTest";public BroadcastReceiverTest() {Log.i(TAG, "BroadcastReceiverTest()");}@Overridepublic void onReceive(Context context, Intent intent) {Log.i(TAG, "onReceive()");}}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="org.wp.activity"      android:versionCode="1"      android:versionName="1.0">    <uses-sdk android:minSdkVersion="4" />    <application android:icon="@drawable/icon" android:label="@string/app_name">        <activity android:name=".BroadcastReceiverActivity"                  android:label="@string/app_name">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity><receiver android:name=".BroadcastReceiverTest"><intent-filter><action android:name="android.intent.action.EDIT" /></intent-filter></receiver>    </application></manifest>

更多相关文章

  1. Android(微信收藏)公号文章分类
  2. Android的消息机制源码分析(4)- Handler
  3. 浅析Android中的消息机制
  4. Android(安卓)Looper中的MessageQueue消息处理机制
  5. Android(安卓)四大组件,五大存储,六大布局
  6. Android(安卓)电话的反射调用机制实现静默接听电话
  7. Android(安卓)Binder 机制详解
  8. Android(安卓)P签名机制和系统权限
  9. Android权限列表permission说明 [轉載]

随机推荐

  1. Android(安卓)apk应用程序签名
  2. Android(安卓)6种快速开发框架
  3. Android(安卓)Camera Hal 的初步实现1
  4. php脚本生成google play url的下载链接,下
  5. Android之Handle的使用[二]
  6. Android(安卓)中Uri的用法汇总
  7. Android(安卓)ril原生代码(C/C++)和java代码部
  8. Android横竖屏切换正确实现方式
  9. Android中TextView的某一关键字高亮显示
  10. Android任务和返回栈完全解析