我在使用Intent传递arrayList时遇到问题。当搜索完成并运行ACTION_DISCOVERY_FINISHED时,应用程序就会停止运行。
DesafioActivity:(发送者)
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
mDeviceList = new ArrayList<BluetoothDevice>();
mProgressDlg.show();
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
mProgressDlg.dismiss();
Intent newIntent = new Intent(DesafioActivity.this, DeviceListActivity.class);
newIntent.putParcelableArrayListExtra("device.list", mDeviceList);
startActivity(newIntent);
} else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = (BluetoothDevice) intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mDeviceList.add(device);
showToast("Dispositivo Encontrado " + device.getName());
}
}
};
DevicesListActivity;(接收机)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paired_devices);
mDeviceList = getIntent().getExtras().getParcelableArrayList("device.list");
mListView = (ListView) findViewById(R.id.lv_paired);
mAdapter = new DeviceListAdapter(this);
mAdapter.setData(mDeviceList);
mAdapter.setListener(new DeviceListAdapter.OnPairButtonClickListener() {
@Override
public void onPairButtonClick(int position) {
BluetoothDevice device = mDeviceList.get(position);
if (device.getBondState() == BluetoothDevice.BOND_BONDED) {
unpairDevice(device);
} else {
showToast("Pairing...");
pairDevice(device);
}
}
});
logcat的:
12-31 17:33:04.510: E/AndroidRuntime(14779): FATAL EXCEPTION: main
12-31 17:33:04.510: E/AndroidRuntime(14779): Process: com.AMOV.mr.fit, PID: 14779
12-31 17:33:04.510: E/AndroidRuntime(14779): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.adapter.action.DISCOVERY_FINISHED flg=0x10 } in com.AMOV.mr.fit.DesafioActivity$1@4198efa8
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:785)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.os.Handler.handleCallback(Handler.java:733)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.os.Handler.dispatchMessage(Handler.java:95)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.os.Looper.loop(Looper.java:136)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.ActivityThread.main(ActivityThread.java:5144)
12-31 17:33:04.510: E/AndroidRuntime(14779): at java.lang.reflect.Method.invokeNative(Native Method)
12-31 17:33:04.510: E/AndroidRuntime(14779): at java.lang.reflect.Method.invoke(Method.java:515)
12-31 17:33:04.510: E/AndroidRuntime(14779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
12-31 17:33:04.510: E/AndroidRuntime(14779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
12-31 17:33:04.510: E/AndroidRuntime(14779): at dalvik.system.NativeStart.main(Native Method)
12-31 17:33:04.510: E/AndroidRuntime(14779): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.AMOV.mr.fit/com.AMOV.mr.fit.DeviceListActivity}; have you declared this activity in your AndroidManifest.xml?
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.Activity.startActivityForResult(Activity.java:3424)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.Activity.startActivityForResult(Activity.java:3385)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.Activity.startActivity(Activity.java:3627)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.Activity.startActivity(Activity.java:3595)
12-31 17:33:04.510: E/AndroidRuntime(14779): at com.AMOV.mr.fit.DesafioActivity$1.onReceive(DesafioActivity.java:149)
12-31 17:33:04.510: E/AndroidRuntime(14779): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:775)
12-31 17:33:04.510: E/AndroidRuntime(14779): ... 9 more
12-31 17:33:06.855: I/Process(14779): Sending signal. PID: 14779 SIG: 9
答案 0 :(得分:1)
未在AndroidManifest.xml中声明DeviceListActivity