Specific function to get LC when LinphoneManager may be already destroyed.
This commit is contained in:
parent
b78cf07c2f
commit
050a943723
2 changed files with 17 additions and 5 deletions
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue