Home BadTokenException when call alertdialog in ValueEventListener onDataChange
Reply: 0

BadTokenException when call alertdialog in ValueEventListener onDataChange

user1634
1#
user1634 Published in August 15, 2018, 5:38 am

android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@e95f236 is not valid; is your activity running?

Use alertdialog in the Firebee event listener as shown below.

Often an error occurs in the listener.

private ValueEventListener mInviteListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

            String token = (String) dataSnapshot.getValue();
            if (token != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setMessage("accep??");
                builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ownerLayoutShowHide(OwnerStatus.INIT);

                    }
                });
                builder.setNegativeButton("no", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                                                }
                });
                builder.setCancelable(false);
                mInvitationAlertDialog = builder.create();

                if (!mInvitationAlertDialog.isShowing()) {
                    mInvitationAlertDialog.show();
                }


            } else {
                //none
            }

    }

    @Override
    public void onCancelled(DatabaseError databaseError) {

    }
};
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.506865 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO