![]() But this may limit the function of our program Therefore, if you still pass in the static variable and pop up the dialog box through a static class, you will get the above error that you can’t find the windowįor errors in the tab page, you can use the context of its parent class to pop up the dialog If the interface has been destroyed, you can only judge whether the interface exists and then pop it upįor the use of static context to pop-up dialog can be solved by circumvention, such as to avoid static context being modified. The static context is the context of the view that has just been finished. Therefore, when the new interface is finished, it returns to the previous interface. ![]() However, if this static context is only initialized in the construction method, there will be problems, because if another interface is created, and the view of binding data is also used, then the static context will be modified again In this way, we can pop up the dialog box through a static class, just pass in the static context (mcontextnew) In its construction method, we initialize a static variable mcontextnew as mcontext of this view. Getapplicationcontext () can’t, because it doesn’t represent any activity or view. Of course, not all static contexts can be used to create a dialog. In this way, we need to provide a static context to create the dialog or toastįor example, we use a static class to pop up a dialog box in a viewĪlertDialog.Builderbuilder=newAlertDialog.Builder(mContextNew) In addition, many times we need to call a view class method through a non component class to pop up the dialog or toast. Where can the problem be solved: when the interface is destroyed, it will pop up again Or when the interface jumps, our view changes, the context attached to dialog changes, or the interface doesn’t run The root cause of this problem is that the view to which the dialog will pop up does not existĢ. We can also understand the reason from the error message. isyouractivityrunning?Ī(ViewRootImpl.java:546)Ī(WindowManagerImpl.java:302)Ī(WindowManagerImpl.java:216)Ī$CompatModeWrapper.addView(WindowManagerImpl.java:141)Ī$LocalWindowManager.addView(W indow.java:537)Ī(Dialog.java:278)Ī$Builder.show(AlertDialog.java:991)Ī(TextView.java:8430)Ī(View.java:5553)Ī(ViewGroup.java:2027)Ī oup.dispatchTransformedTouchEvent(ViewGroup.java:2027)Ī(ViewGroup.java:1762)Ī.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)Ī.(PhoneWindow.java:1397)Ī ity.dispatchTouchEvent(Activity.java:2431)Ī(NativeMethod) A common mistake about Android: unable to add window - token is not validĪ$BadTokenException:Unabletoaddwindow–tokenandroid.os. Programmer algorithm practice must read, common Java API skills to share> =4.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |