几个小时以来,我一直试图找出这里出了什么问题。为什么这个广播接收器没有收到意图?
static class BReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
Toast.makeText(context, "Got the intent", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLayout = new FrameLayout(this);
setContentView(mLayout);
final IntentFilter intentFilter = new IntentFilter("com.example.testui.action");
getApplicationContext().registerReceiver(new BReceiver(), intentFilter);
final Intent intent = new Intent(getApplicationContext(), BReceiver.class);
intent.setAction("com.example.testui.action");
getApplicationContext().sendBroadcast(intent);
}
PS。我没有在清单文件中定义这个接收器,因为严格地说,它不是强制性的。