Problem:
There is a noticeable delay - of around 40-50+ seconds, from the time the application is launched on the wearable to the point the DatalayerService is started.
Evidence:
09-15 10:19:09.594 455-475/? I/ActivityManager﹕ Displayed com.test.watches/.WatchfaceActivity: +860ms
09-15 10:20:05.104 1775-1775/? V/Watchface﹕ Starting up Google api client
09-15 10:20:05.234 1775-1775/? V/Watchface﹕ Called connect on google api client in onCreate()
Clearly from the timestamps there is a delay of around 55 seconds, from the time the user starts up the application on the wearable to the point the data transfer starts.
This is unacceptable since the user will simply assume that the code is buggy.
My code looks like the typical workflow. After the connection establishes - things run smoothly, however, on bootup or on a fresh install of the app, connecting to the data layer takes for ever!!
My code:
public class DataLayerListenerService extends WearableListenerService {
private static final String TAG = "Watchface";
GoogleApiClient mGoogleApiClient;
@Override
public void onCreate() {
super.onCreate();
Log.v("Watchface", "Starting up Google api client");
mGoogleApiClient = new GoogleApiClient.Builder(getApplicationContext())
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle connectionHint) {
Log.i(TAG, "onConnected: " + connectionHint);
}
@Override
public void onConnectionSuspended(int cause) {
Log.i(TAG, "onConnectionSuspended: " + cause);
}
})
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "onConnectionFailed: " + result);
}
})
.addApi(Wearable.API)
.build();
mGoogleApiClient.connect();
Log.v("Watchface", "Called connect on google api client in onCreate()");
}
At this point I am contemplating manually booting up the DataLayerListenerService in onCreate() of my main activity. I dont think that is recommended practice - but I'm not sure if I have much option.