Dialog throwing "Unable to add window — token null is not for an application” with getApplication() as context

前端 未结 28 1375
死守一世寂寞
死守一世寂寞 2020-11-22 08:42

My Activity is trying to create an AlertDialog which requires a Context as a parameter. This works as expected if I use:

AlertDialog.Builder builder = new Al         


        
28条回答
  •  渐次进展
    2020-11-22 08:54

    adding

    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    

    and

    "android.permission.SYSTEM_ALERT_WINDOW"/> in manifest

    It works for me now. After even close and open the application, gave me the error at that time.

提交回复
热议问题