Workaround core instanciation fragility

During core creation the globalstate callback is
triggered before the java object is instantiated.

Code in listener try to access the core object.
This commit is contained in:
Guillaume Beraudo 2011-12-02 11:58:37 +01:00
parent d3bc9e7e6c
commit 1cca9a7b84

View file

@ -324,7 +324,8 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
mNotif.iconLevel = level;
mNotif.when=System.currentTimeMillis();
String text = getString(textId);
if (text.contains("%s")) {
if (text.contains("%s") && LinphoneManager.getLc() != null) {
// Test for null lc is to avoid a NPE when Android mess up badly with the String resources.
LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
String id = lpc != null ? lpc.getIdentity() : "";
text = String.format(text, id);
@ -376,12 +377,15 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
if (state == GlobalState.GlobalOn) {
sendNotification(IC_LEVEL_OFFLINE, R.string.notification_started);
mHandler.post(new Runnable() {
// Slightly delay the propagation of the state change.
// This is to let the linphonecore finish to be created
// in the java part.
mHandler.postDelayed(new Runnable() {
public void run() {
if (guiListener() != null)
guiListener().onGlobalStateChangedToOn(message);
}
});
}, 50);
}
}