这段代码不起作用。发生了什么?
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
registerReceiver(br, new IntentFilter("a.b.c.d"));
Intent it = new Intent("a.b.c.d");
startActivity(it);
}
BroadcastReceiver br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "test", Toast.LENGTH_SHORT);
}
};
}
错误:
01-22 10:55:21.812: ERROR/AndroidRuntime(10405): java.lang.RuntimeException: Unable to start activity ComponentInfo{sample.intent.broadcast/sample.intent.broadcast.Main}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=a.b.c.d }
发布于 2012-01-22 04:32:20
如果您只是尝试测试接收器,请将startActivity(it)
替换为sendBroadcast(it)
。
发布于 2012-01-22 04:50:37
a.b.c.d不是登记的意图。使用已存在的活动。检查您的清单文件或标准应用程序的意图列表。
https://stackoverflow.com/questions/8958910
复制相似问题