Search code examples
android-intentsipfloating-action-button

floating action button doesnt show with show()?


I am creating a simple sipcall using Android native sip stack. I wish to show a particular floating action button on successful sip connection and hide the same floating action button on unsuccessful sip connection. By default floating action button is shown. Some how show part doesnt works and couldnt find any solution why. Working on android version 27. Below is the part of implementation of sip profile.

                        /**
                         * Name: onRegistrationDone
                         * Description: Logs a status message indicating the
                         *              SipProfile successfully registered.
                         */
                        public void onRegistrationDone(String localProfileUri, long expiryTime) {



                            Log.e("$$", "Sip Profile <" + localProfileUri + "> successfully registered");
                            System.out.println( " login successful");

// i am showing floating action button on successful registration -doesnt works

                        FloatingActionButton fab3 = (FloatingActionButton) findViewById(R.id.fab3);
                        fab3.show();
                        }

                        /**
                         * Name: onRegistrationFailed
                         * Description: Logs a status message indicating the
                         *              SipProfile failed to register.
                         */
                        public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {

// hiding floating action button -which works

                            FloatingActionButton fab3 = (FloatingActionButton) findViewById(R.id.fab3);

                            fab3.hide();


                            Log.e("$$", "Sip Profile failed to register <" + localProfileUri + "> " +
                                    " Error message: " + errorMessage);
                            System.out.println( " login unsuccessful. Error message:" + errorMessage);
                        }
                    });
        } catch (ParseException e) {
            Log.e("$$", "SipProfile was not built.");
            e.printStackTrace();
        } catch (SipException e) {
            e.printStackTrace();
        }
    }
}

Error

android.util.AndroidRuntimeException: Animators may only be run on Looper threads
        at android.animation.ValueAnimator.start(ValueAnimator.java:969)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1010)
        at android.animation.AnimatorSet.start(AnimatorSet.java:678)
        at android.animation.AnimatorSet.onChildAnimatorEnded(AnimatorSet.java:807)
        at android.animation.AnimatorSet.start(AnimatorSet.java:640)
        at com.google.android.material.floatingactionbutton.FloatingActionButtonImpl.hide(FloatingActionButtonImpl.java:423)
        at com.google.android.material.floatingactionbutton.FloatingActionButton.hide(FloatingActionButton.java:540)
        at com.google.android.material.floatingactionbutton.FloatingActionButton.hide(FloatingActionButton.java:536)
        at com.google.android.material.floatingactionbutton.FloatingActionButton.hide(FloatingActionButton.java:525)
        at com.serv24.eframe.MediaPresentationActivity$16.onRegistrationFailed(MediaPresentationActivity.java:1550)
        at android.net.sip.SipManager$ListenerRelay.onRegistrationFailed(SipManager.java:652)
        at android.net.sip.ISipSessionListener$Stub.onTransact(ISipSessionListener.java:180)
        at android.os.Binder.execTransact(Binder.java:573)

Solution

  • Please try this, it may be helpful :

    runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    fab3.show();
                }
            });