喜的朋友,我不能從一個活動到其他活動發送廣播請參見下面我的代碼和幫助:無法從活動發送廣播:安卓
public class SendBroadcast extends Activity {
public static String BROADCAST_ACTION = "com.unitedcoders.android.broadcasttest.SHOWTOAST";
/* }
});
}
public void sendBroadcast(){
Intent broadcast = new Intent("com.unitedcoders.android.broadcasttest.SHOWTOAST");
this.sendBroadcast(broadcast);
//startActivity(broadcast);
}
}
接收端代碼:
public class ToastDisplay extends Activity {
private BroadcastReceiver mReceiver;
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.i("[email protected]@@@@@@$$$$","%%%%%%% msg_for_me");
ent // String msg_for_me = intent.getStringExtra(「some_msg」); //記錄我們的留言值 Log.i(「!!!!!!! InchooTutorial @@@@@@@ $$$$」,「%%%%%%% msg_for_me」);
}
};
//registering our receiver
this.registerReceiver(mReceiver, intentFilter);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
//unregister our receiver
this.unregisterReceiver(this.mReceiver);
}
}
的Manifest.xml是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unitedcoders.android.broadcasttest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".SendBroadcast"
android:label="@string/app_name">
<intent-filter>
nitedcoders.android.broadcasttest.SHOWTOAST" />
</application> </manifest>
您是否已將接收器添加到清單中? – 2012-04-25 09:40:12
請參考我的清單文件.. – shyam 2012-04-25 09:57:49