I make an application with Linphone Library, I have a code to throw an exception in MainActivity like this :
private static MainActivity instance;
public static final boolean isInstanciated() {
return instance != null;
}
public static final MainActivity instance() {
if (instance != null) {
return instance;
}
throw new RuntimeException("LinphoneActivity not instantiated yet");
}
Method instance will be used in another activity (IncomingCallActivity and Contact Data Activity)
Incoming Call Activity will launch if there is a call to the phone
if (!LinphoneManager.getInstance().acceptCallWithParams(mCall, params)) {
// the above method takes care of Samsung Galaxy S
Toast.makeText(this, R.string.couldnt_accept_call, Toast.LENGTH_LONG).show();
} else {
if (!MainActivity.isInstanciated()) {
return;
}
final LinphoneCallParams remoteParams = mCall.getRemoteParams();
if (remoteParams != null && remoteParams.getVideoEnabled() && LinphoneManager.getInstance().isAutoAcceptCamera()) {
MainActivity.instance().startVideoActivity(mCall);
} else {
MainActivity.instance().startIncallActivity(mCall);
}
}
ContactDataActivity will launch if user choose contact menu
private void doCall(String number) {
Log.d(TAG, "try to call here: " + number);
if (Account.isPrepaidRegistered()) {
MainActivity.instance().requestToCall(number);
} else {
Intent intent = new Intent(ContactDataActivity.this, PrepaidRegisterActivity.class);
startActivity(intent);
}
}
Where each of that activity need to call instance of MainActivity to call method in MainActivity to requestcall or incall.
some time when running the app, logcat will show :
java.lang.RuntimeException: LinphoneActivity not instantiated yet
Is that just normal, or there is something wrong with my code ?