diff --git a/src/org/linphone/DialerActivity.java b/src/org/linphone/DialerActivity.java index 34de67cc9..7e99f58e0 100644 --- a/src/org/linphone/DialerActivity.java +++ b/src/org/linphone/DialerActivity.java @@ -385,7 +385,7 @@ public class DialerActivity extends SoftVolumeActivity implements LinphoneGuiLis public void onCallStateChanged(LinphoneCall call, State state, String message) { - LinphoneCore lc = LinphoneManager.getLc(); + LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc==null) { /* we are certainly exiting, ignore then.*/ return; diff --git a/src/org/linphone/LinphoneManager.java b/src/org/linphone/LinphoneManager.java index c3c74740c..6c1e35430 100644 --- a/src/org/linphone/LinphoneManager.java +++ b/src/org/linphone/LinphoneManager.java @@ -214,13 +214,16 @@ public final class LinphoneManager implements LinphoneCoreListener { public static synchronized final LinphoneManager getInstance() { if (instance != null) return instance; - if (!sExited) throw new RuntimeException("Linphone Manager should be created before accessed"); - return null; + if (sExited) { + throw new RuntimeException("Linphone Manager was already destroyed. " + + "Better use getLcIfManagerNotDestroyed and check returned value"); + } + + throw new RuntimeException("Linphone Manager should be created before accessed"); } public static synchronized final LinphoneCore getLc() { - LinphoneManager m=getInstance(); - return m!=null ? m.mLc : null; + return getInstance().mLc; } @@ -916,5 +919,14 @@ public final class LinphoneManager implements LinphoneCoreListener { return distanceInCm < threshold; } + public static synchronized LinphoneCore getLcIfManagerNotDestroyedOrNull() { + if (sExited) { + // Can occur if the UI thread play a posted event but in the meantime the LinphoneManager was destroyed + // Ex: stop call and quickly terminate application. + Log.w("Trying to get linphone core while LinphoneManager already destroyed"); + return null; + } + return getLc(); + } }