1

Bellow my code is login twilio client is working

public void login(final String clientName,
                          final boolean allowOutgoing,
                          final boolean allowIncoming) {
            if (loginListener != null)
                loginListener.onLoginStarted();

            this.lastClientName = clientName;
            this.lastAllowOutgoing = allowOutgoing;
            this.lastAllowIncoming = allowIncoming;

            if (!twilioSdkInited) {
                if (twilioSdkInitInProgress)
                    return;

                twilioSdkInitInProgress = true;
                Twilio.setLogLevel(Log.DEBUG);

                Twilio.initialize(context, new Twilio.InitListener() {
                    @Override
                    public void onInitialized() {

                        Log.e(TAG, "onInitialized");
                        twilioSdkInited = true;
                        twilioSdkInitInProgress = false;
                        obtainCapabilityToken(clientName, allowOutgoing, allowIncoming);
                    }

                    @Override
                    public void onError(Exception error) {
                        Log.e(TAG, "onInitialized onError :" + error.toString());
                        Log.e(TAG, " onInitialized onError : isTokenExpired is Blank");
                        twilioSdkInitInProgress = false;

                        if (loginListener != null)
                            loginListener.onLoginError(error);
                    }

                    @Override
                    protected void finalize() throws Throwable {

                        Log.e(TAG, "@call finalize()");
                        if (device != null)
                            device.release();
                        if (connection != null)
                            connection.disconnect();
                        super.finalize();
                    }
                });
            } else {
                Log.e(TAG, "twilioSdkInited obtainCapabilityToken");
                obtainCapabilityToken(clientName, allowOutgoing, allowIncoming);
            }

Below logs are error generate some time when relaunch my app.

07-06 10:10:14.265 32611-32611/com.reach.communications E/NewCallScreenActivity: @call onLoginStarted
07-06 10:10:14.265 32611-32611/com.reach.communications I/PJSIP: 10:10:14.265 sip_endpoint.c !Module "mod-pjsua-log" unregistered
07-06 10:10:14.265 32611-32611/com.reach.communications I/PJSIP: 10:10:14.265 sip_endpoint.c  Module "mod-pjsua-log" registered
07-06 10:10:14.265 32611-32611/com.reach.communications E/BasicPhone: onInitialized onError :java.lang.RuntimeException: Twilio.initialize() already called
07-06 10:10:14.265 32611-32611/com.reach.communications E/BasicPhone:  onInitialized onError : isTokenExpired is Blank
07-06 10:10:14.265 32611-32611/com.reach.communications E/NewCallScreenActivity: @call onLoginError :java.lang.RuntimeException: Twilio.initialize() already called
07-06 10:10:14.265 32611-32611/com.reach.communications E/NewCallScreenActivity: @Call State idle

How to Handle if i am getting this error and re-login client. or How to re-initialize twilio.

onError(Exception error)

thanks in advance

Tim
  • 41,901
  • 18
  • 127
  • 145
Android Devs
  • 125
  • 13

1 Answers1

1

I see you are trying .release(). What happens if you use the .shutdown() method? This will terminate all connections, release all Device objects, and release any resources used by the SDK.

Then you can safely call .initialize() again before the next call.

Additionally, you can use .isInitialized() to determine if the Client is ready or not.

Please let me know if any of these changes help.

Megan Speir
  • 3,745
  • 1
  • 15
  • 25