简体   繁体   中英

how to pass bluetooth device name to another activity?

i am trying to pass Bluetooth device name and RSSI from one activity that contain the ListView to another activity,it works fine when the user choose one device but when the user choose another device the result will be the same for the first device. is there away to pass the name and RSSI or a Bluetooth device ??

newDevicesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mBtAdapter.cancelDiscovery();
           Intent intent = new Intent(DevicesList.this, FindIT.class);
            intent.putExtra("name", NAME);
            intent.putExtra("rssi", RSSI);
            startActivity(intent);
        }
    });

here is the code i use to send the intent

Maybe you are looking for something like this:

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("BLUETOOTH_NAME", bluetoothName);
intent.putExtra("RSSI", rssi);
startActivity(intent);

In this case you save your data in the intent and pass it to the next activity every time you go from one activity to another. Then you can get your data in the new activity like this:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String bluetoothName = extras.getString("BLUETOOTH_NAME");
    String rssi = extras.getString("RSSI");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM