[英]data is not received from intent
我正在使用BLE。 我正在尝试使用打算将rssi值从一项活动发送到另一项活动。
活动1 ,当rssi信号发生变化时,我将值发送过来,如下所示:
@Override
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
//first logcat
Log.d("BLE_Strength_connected", String.format("BluetoothGatt ReadRssi[%d]", rssi));
Intent i = new Intent(Activity1.this, Activity2.class);
i.putExtra("key",rssi);
startActivity(i);
}
}
};
活动2:在oncreate()方法中,我启动了一个处理程序,它每秒读取一次数据,我具有以下内容:
mIntent = getIntent();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
try {
mHandler.postDelayed(this, 1000);
// if (mIntent != null) {
int value = mIntent.getIntExtra("key", 0);
Log.d("retrieve_RSSI", "value:" + value);
//The key argument here must match that used in the other activity
// }
}catch (Exception e) {
}
}
}, 1000);
我在活动1上的logcat一直在打印rssi信号,但是在活动2上的logcat仅打印零。 我想知道为什么我不能在活动2中收到任何值?
您的mIntent变量将始终引用相同的Intent对象,因此,当您从中另外提取“键”时,您当然将始终获得相同的值。
您必须确保处理新的传入意图。 请参阅例如http://m.helloandroid.com/tutorials/communicating-between-running-activities如何执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.