Fixing a crash caused by using implicit intent when starting a service
Due to a change in the Android framework, we need to use explicit
intents when starting a service and this issue makes a change to
comply with that in this sample.
Bug: 21232620
Change-Id: I53973168c7ce16170560f691030c44d9d824c38c
diff --git a/wearable/wear/ElizaChat/Application/src/main/java/com/example/android/wearable/elizachat/MainActivity.java b/wearable/wear/ElizaChat/Application/src/main/java/com/example/android/wearable/elizachat/MainActivity.java
index 982e3de..2e132a8 100644
--- a/wearable/wear/ElizaChat/Application/src/main/java/com/example/android/wearable/elizachat/MainActivity.java
+++ b/wearable/wear/ElizaChat/Application/src/main/java/com/example/android/wearable/elizachat/MainActivity.java
@@ -55,11 +55,12 @@
}
};
mHistoryView = (TextView) findViewById(R.id.history);
- startResponderService();
+ startResponderService(ResponderService.ACTION_INCOMING);
}
- private void startResponderService() {
- Intent serviceIntent = new Intent(ResponderService.ACTION_INCOMING);
+ private void startResponderService(String action) {
+ Intent serviceIntent = new Intent(this, ResponderService.class);
+ serviceIntent.setAction(action);
startService(serviceIntent);
}
@@ -69,9 +70,7 @@
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
new IntentFilter(ACTION_NOTIFY));
mHistoryView.setText("");
- Intent serviceIntent = new Intent(ACTION_GET_CONVERSATION);
- startService(serviceIntent);
-
+ startResponderService(ACTION_GET_CONVERSATION);
}
@Override