creating mobile companion for my Garmin App I faced circular dependency error (on watch) with the following implementation
function onStart() {
...
Comm.setMailboxListener( method(:onMail) );
...
}
...
function onMail(mailIter) {
Sys.println("received mail");
var mailStr = mailIter.next();
while( mailStr != null ) {
Sys.println("processing mailbox string = "+ mailStr);
getApp().setProperty("testProperty", mailStr);
mailStr = mailIter.next();
}
Comm.emptyMailbox();
}
Similar to the problem with using Drawable in Picker, this doesn't prevent app to work properly, but gives "circular dependency" error in log.
I decided to try and set up BLE simulation over ADB as stated in Programmer's guide. After recommended action sequence, I was able to connect to Simulator, but when I send message from Android app I do not receive status update and Simulator doesn't show any of the expected log messages most possibly meaning that message never arrived. Code excerpt from my Android app:
private void sendMessageDevices() {
final String iqMessage = "test message";
try {
List<IQDevice> devices = mConnectIQ.getKnownDevices();
if (devices != null && devices.size() > 0) {
// get the status of the devices
Log.d("smartComp", "processing iq devices");
for (final IQDevice device : devices) {
IQDevice.IQDeviceStatus status = mConnectIQ.getDeviceStatus(device);
if (status == IQDevice.IQDeviceStatus.CONNECTED) {
Log.d("smartComp", "processing connected iq device");
// Work with the device
mConnectIQ.getApplicationInfo(THE_SMART_ID, device,
new ConnectIQ.IQApplicationInfoListener() {
@Override
public void onApplicationInfoReceived(IQApp iqApp) {
Log.d("smartComp", "application installed, sending message");
if (iqApp != null) {
if (iqApp.getStatus() == IQApp.IQAppStatus.INSTALLED) {
sendMessageIQDevice(device, iqApp, iqMessage);
}
}
}
@Override
public void onApplicationNotInstalled(String s) {
Log.d("smartComp", "application not installed");
}
});
}
}
}
} catch (InvalidStateException e) {
// This generally means you forgot to call initialize(), but since
// we are in the callback for initialize(), this should never happen
} catch (ServiceUnavailableException e) {
// This will happen if for some reason your app was not able to connect
// to the ConnectIQ service running within Garmin Connect Mobile. This
// could be because Garmin Connect Mobile is not installed or needs to
// be upgraded.
e.printStackTrace();
}
}
...
private void sendMessageIQDevice(IQDevice device, IQApp iqApp, String message) {
try {
mConnectIQ.sendMessage(device, iqApp, message, new ConnectIQ.IQSendMessageListener() {
@Override
public void onMessageStatus(IQDevice device, IQApp app, ConnectIQ.IQMessageStatus status) {
Toast.makeText(SmartCompanion.this, status.name(), Toast.LENGTH_LONG).show();
}
});
} catch (InvalidStateException e) {
Toast.makeText(this, "ConnectIQ is not in a valid state", Toast.LENGTH_LONG).show();
} catch (ServiceUnavailableException e) {
Toast.makeText(this, "ConnectIQ service is unavailable. Is Garmin Connect Mobile installed and running?", Toast.LENGTH_LONG).show();
}
}
...
I get all of the log messages up to send message function where I expect to receive message status in onMessageStatus callback.
Just to make it clear: this works as expected over BLE with actual device if I change ConnectIQ.IQConnectType.TETHERED to ConnectIQ.IQConnectType.WIRELESS in ConnectIQ.getInstance.
So, I just want to get rid of circular dependency error in CIQ app, which appears only if app is trying to process received "mail".
To do this, I tried to set up BLE emulation, but this doesn't work as expected.
Can someone, please, give any piointers on how to proceed?
Thanks in advance.
P.S. repetitive testing on watch shows, that circular dependency error appears in log only in case onMail callback is called.
I even tried to add some kind of finalization to this listener during application stop to no avail. So, it's either another bug in SDK or correct mail listener lifecycle is not described fully in documentation.
function onStop() {
...
Comm.setMailboxListener( null );
...
}