Android学习笔记(十九)
16lz
2022-03-14
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>
更多相关文章
- Android(微信收藏)公号文章分类
- Android的消息机制源码分析(4)- Handler
- 浅析Android中的消息机制
- Android(安卓)Looper中的MessageQueue消息处理机制
- Android(安卓)四大组件,五大存储,六大布局
- Android(安卓)电话的反射调用机制实现静默接听电话
- Android(安卓)Binder 机制详解
- Android(安卓)P签名机制和系统权限
- Android权限列表permission说明 [轉載]