WindowManager=(WindowManager)getSystemService(WINDOW_SERVICE) Ĭopy_tImageResource(R.drawable.ic_launcher) Ĭopy_tOnClickListener(new void onClick(View arg0) WindowManager.LayoutParams IBinder onBind(Intent arg0) Still want to inherit from AppCompatActivity, then use AppCompat's theme according to the prompt, that is, change the theme configuration of Activity in the AndroidManifest.I am trying to put a feature of a custom popup menu that shows up when the user clicks on the floating icons.įloating icon code: public class copy_actions_service extends Service My Activity inherits 4.app.FragmentActivity, and the problem still exists after directly inheriting Activity. Public class MainActivity extends ActionBarActivity Changed to activity inherited from Activity: If the activity is inherited from AppCompatActivity: When creating an activity, if it is not so strongly necessary to inherit from AppCompatActivity, directly inherit Activity. If the first rule is not satisfied, there will be no permission flashback, and if the second rule is not satisfied, there will be no Toast. Need to add to the app to add system Dialog popup permissions and apply for permissions dynamically. Permission issues caused by some unstable MIUI system bugs, the system regards Toast as a system-level pop-up window, android6.0 system Dialog pop-up window requires user manual authorization, if the app does not add SYSTEM_ALERT_WINDOW permission will report this wrong. On the 4.6.0 system, (non-customized rom behavior) if the floating window permission is not given, the problem will pop up, you can use Settings.canDrawOverlays to determine whether the permission is available.ĥ. You need to add dialog.getWindow().SetType(_SYSTEM_ALERT) before calling the dialog.show() method. When the Service&Application pop-up dialog box or WindowManager adds a view, the window type is not set to TYPE_SYSTEM_ALERT. It is recommended to determine whether the Activity has been destroyed before Dialog calls the show method (the situation I encountered) 。ģ. If the Activity is destroyed, the Dialog window carrier cannot be found. When the Dialog calls the show method for display, there must be an Activity as the carrier of the window. Refresh at the UI level, we must pay attention to the timing, it is recommended to use set_result to replace the form of broadcasting for refresh operations, to avoid the use of broadcasting, the code is not intuitive and error-prone.Ģ. If the Activity before this time performs UI level operation processing, it will cause a crash. When there is no destroy on the previous page, the previous Activity has received the broadcast. Several common scenarios are as follows:ġ. postDelayed ( new Runnable ( ) void run ( ), 2000 ) Main error logĪ$BadTokenException Unable to add window – token null is not for an applicationġ (ViewRootImpl.java:683) 2 (WindowManagerGlobal.java:342) 3 (WindowManagerImpl.java:93) 4 (Dialog.java:329) .dispatchKeyEvent(PadNumKeyboardManager.java:117) .HomeActivity.dispatchKeyEvent(HomeActivity.java:183) 7 .DecorView.dispatchKeyEvent(DecorView.java:451) Analysis of the reason The exception indicates that the window cannot be added, usually caused by the view that the view to be attached no longer exists.ĭialog&AlertDialog, when WindowManager cannot be used correctly, this exception is often reported. Android $BadTokenException Original code // An highlighted blockįinal AlertDialog alert = new AlertDialog.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |