我使用Linphone库创建一个应用程序,我有一个代码在MainActivity中抛出异常,如下所示:
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");
}
方法实例将用于另一个活动(IncomingCallActivity和Contact Data Activity)
如果有来电的话,将启动来电活动
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);
}
}
如果用户选择联系人菜单
,将启动ContactDataActivityprivate 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);
}
}
其中每个活动都需要调用MainActivity实例来调用MainActivity中的方法来请求调用或调用。
运行应用程序时,logcat将显示:
java.lang.RuntimeException:LinphoneActivity尚未实例化
这是正常的,还是我的代码有问题?