Reputation: 326
I have previously worked with iOS and Bluetoot Low Energy, now I need this to work on android aswell. With iOS there were such things as delegate methods. I changed the BLE characteristic's values on one view and passed the updated values to the previous view, which had established the connection. This view then immediatly transferred the new values to the BLE periphereal.
pseudo code:
[_delegate setDeviceDateTime:[NSDate now]];
The problem is that i can't find such a thing with android. The parent activity holds the BluetoothGatt, which can update the periphereal's values. Im looking for something like the following:
pseudo code current view:
getParent().setDeviceDateTime(new Date());
pseudo code parent view:
public void setDeviceDateTime(Date date) {
BluetoothGattCharacteristic myCharacteristic = getCharacteristic(dateTime);
myCharacteristic.setValue(date);
myGatt.writeCharacteristic(myCharacteristic);
}
It seems that im way too stuck thinking the way I did with iOS, I cant seem to find a solution..
EDIT:
Okay so I need to access the parent activity wile the current activity is still active, so startActivityForResult()
wouldnt work.
Basically I need to push a Button, transfer a String to the parent activity which processes it and transfers it to the peripheral via BLE. And to change some other settings while still being (and staying) connected with the peripheral without dismissing the "settings activity".
Upvotes: 0
Views: 122
Reputation: 1699
Your use case is not entirely clear, but it seems you need to look into StartActivityForResult()
You can execute the second activity with startActivityForResult()
so when the second activity is done it can transfer information back to the main activity.
If, however, you need to notify the main activity while the second one is still active it won't work. In that case I would change the design: In Android an activity is a UI component, a screen. And Android isn't built to have screens 'working' (e.g. communicating with BT) while not in the foreground.
You need some kind of 'global' BT controller that can be accessed from multiple activities. Two ways to do it (there may be more):
In both cases any activity will have access to the Application's/service's methods, and will be able to use the blue tooth, alter it's settings, etc.
Upvotes: 1