BadTokenException: Impossible d'ajouter de la fenêtre — jeton de la valeur null n'est pas valide; est votre activité en cours d'exécution? dans l'activité.isFinishing de tresorerie
J'ai un popUpWindow qui doivent être affichés, après quelques secondes si l'utilisateur est toujours sur l'activité en cours. J'ai mis en place stament que de vérifier si l'activité n'est pas fini/détruits et puis afficher la fenêtre Contextuelle, et il fonctionne très bien, pour les week-utilisateurs 🙂 ( cliquant lentement à partir d'une activité à l'autre), mais en haute pressuretests ( activités de recréer, de finition, de déplacement rapide forme d'activité à l'activité) qui me donne cette erreur :
E/UncaughtException: android.vue.WindowManager$BadTokenException:
Impossible d'ajouter de la fenêtre -- jeton de la valeur null n'est pas valide; est votre activité
en cours d'exécution?
au android.vue.ViewRootImpl.setView(ViewRootImpl.java:598)
au
android.vue.WindowManagerGlobal.addView(WindowManagerGlobal.java:341)
au android.vue.WindowManagerImpl.addView(WindowManagerImpl.java:85)
au android.widget de.PopupWindow.invokePopup(PopupWindow.java:1279)
au android.widget de.PopupWindow.showAtLocation(PopupWindow.java:1040)
au android.widget de.PopupWindow.showAtLocation(PopupWindow.java:1003)
au com.guides4art.app.ImageSlider.RatePopUp$3.exécuter(RatePopUp.java:86)
au android.os.Gestionnaire d'.handleCallback(Handler.java:743)
au android.os.Gestionnaire d'.dispatchMessage(Handler.java:95)
au android.os.Looper.boucle(Looper.java:150)
au android.app.ActivityThread.principale(ActivityThread.java:5546)
à java.lang.de réfléchir.La méthode.invoke(Native method)
au
com.android.interne.os.ZygoteInit$MethodAndArgsCaller.exécuter(ZygoteInit.java:794)
au com.android.interne.os.ZygoteInit.principale(ZygoteInit.java:684)
code:
private void showPopUpWindow(final Activity context){
popupWindow = new PopupWindow(context);
LinearLayout.LayoutParams layoutParams =new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
popupWindow.setHeight(layoutParams.height);
popupWindow.setWidth(layoutParams.width);
popupWindow.setOutsideTouchable(true);
popupWindow.setTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setContentView(view);
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
if(context instanceof CarSale) {
((CarSale) context).saveRate((int) rating);
((CarSale) context).initRate();
title.setText(""+context.getString(R.string.thanksForRate));
}
else
Log.i("kamil","error");
}
});
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
if(!context.isFinishing() || !context.isDestroyed() )
activityView.post(new Runnable() {
@Override
public void run() {
popupWindow.showAtLocation(context.getWindow().getDecorView(), Gravity.CENTER,0,0);
}
});
}
//View Pager Class
@Override
public void onPageSelected(int position) {
if(viewPager !=null){
this.position=position;
if(position==carList.size()-1 && isRated() && showRateBar)
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new RatePopUp(Cars.this,activityView);
showRateBar=false;
}
},5*SECOND);
//RatePopUp constructor
public RatePopUp(Activity context,View activityView){
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.rate_popup_layout, null);
this.activityView=activityView;
ratingBar = (RatingBar) view.findViewById(R.id.ratingPop);
title= (TextView)view.findViewById(R.id.rateTitle);
title.setText(context.getString(R.string.rate_exhibition));
closeButton = (Button)view.findViewById(R.id.close_button);
Typeface typeface =Typeface.createFromAsset(context.getAssets(),"fonts/fontawesome-webfont.ttf");
closeButton.setTypeface(typeface);
closeButton.setText(context.getString(R.string.exitIcon));
showPopUpWindow(context);
}
showPopUpWindow
J'ai ajouter le reste du code
OriginalL'auteur Expiredmind | 2017-01-16
Vous devez vous connecter pour publier un commentaire.
essayez ce code:
au lieu de:
Aussi assurez-vous de passer
ActivityName.this
que le contexte.. pasgetApplicationContext
()Essayez de remplacer votre
runnable
code dansshowPopUpWindow()
:j'ai édité le answer...@Expiredmind
OriginalL'auteur rafsanahmad007
Au lieu de
essayer
A bien fonctionné pour moi.
OriginalL'auteur shishir sahoo
Espère que cela va vous aider à...
Remplacer:
avec:
OriginalL'auteur Mahendran Candy