错误是:android.view.WindowManager $ BadTokenException:无法添加窗口

时间:2019-05-01 12:01:02

标签: android dialog

“在我的Android应用中,我使用了弹出窗口,第一次可以正常使用。但是当第二次应用弹出窗口时,崩溃了错误代码为:android.view.WindowManager $ BadTokenException:无法添加窗口- -令牌android.os.BinderProxy@1ad6bb5无效”,请任何人可以对此表示感谢

public class MyAdsMapActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener, RoutingListener 
   private GoogleMap mMap;
    String userId, adId, latitide, longtide,adStatus,buyerId,notificationKey,productName;
    Double sellerLatitude, sellerLongtide;
    GoogleApiClient mGoogleApiClient;
    Location mLastLocation;
    private LatLng sellerLocation;
    private LatLng initBuyerLocation;
    LocationRequest mLocationRequest;
    Button cancelBooking,buttonAccept;
    private List<Polyline> polylines;
    DatabaseReference notificationRef;
    Dialog AdcencelationDialog;
    ImageView closePopupCancelAd;
    TextView messageTv,titleTv;

{


    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_ads_map);
       //popUp
        AdcencelationDialog=new Dialog(this);

             //toListen ad Status
        DatabaseReference adStatusLister= FirebaseDatabase.getInstance().getReference("post_ad_details").child(adId).child("adStatus");
        adStatusLister.addValueEventListener(new ValueEventListener() {

              @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                   String cahngedStatus=dataSnapshot.getValue(String.class);
                    if(cahngedStatus.equals("available")){

                        ShowPopUp();


                    }
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });

}
public void ShowPopUp() {


       // AdcencelationDialog=new Dialog(this);


    AdcencelationDialog.setContentView(R.layout.pop_up_ad_cancellation);
    closePopupCancelAd=(ImageView)AdcencelationDialog.findViewById(R.id.closePopupCancelAd);
    buttonAccept=(Button)AdcencelationDialog.findViewById(R.id.btnAccept);
    titleTv=(TextView)AdcencelationDialog.findViewById(R.id.titleTv);
    messageTv=(TextView)AdcencelationDialog.findViewById(R.id.messageTv);

    AdcencelationDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    AdcencelationDialog.show();
    closePopupCancelAd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           AdcencelationDialog.dismiss();
        }
    });

       buttonAccept.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AdcencelationDialog.dismiss();
            //AdcencelationDialog=null;

            finish();
            //startActivity(intent);

            Intent intent=new Intent(v.getContext(),MyAdsActivity.class);
            startActivity(intent);

        }
    });

}

}

0 个答案:

没有答案