From 1cca9a7b84736338a5721b703d00e3c3b8ad5527 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Fri, 2 Dec 2011 11:58:37 +0100 Subject: [PATCH] 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. --- src/org/linphone/LinphoneService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/org/linphone/LinphoneService.java b/src/org/linphone/LinphoneService.java index 3b18b8b62..8948084b8 100644 --- a/src/org/linphone/LinphoneService.java +++ b/src/org/linphone/LinphoneService.java @@ -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); @@ -375,13 +376,16 @@ public final class LinphoneService extends Service implements LinphoneServiceLis public void onGlobalStateChanged(final GlobalState state, final String message) { 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); } }