I am working with BLE. I am trying to use intend to send rssi value from one activity to another.
Activity 1, when ever there is a change in the rssi signal, I send the values over, shown below:
@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);
}
}
};
Activity 2: In the oncreate() method, I started a handler, and it reads the data every second, I have the following:
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);
My logcat on Activity 1 is constantly prints the rssi signal, but the logcat on activity 2 only prints zero. I am wondering why I can't receive any values in activity 2?