Unable to add window — token null is not valid; is your activity running?

后端 未结 8 1214
花落未央
花落未央 2020-12-01 11:45

i want to show a custom popup menu when user click on a floating icon

the float icon create with an service and i have no activity

this is my floating icon c

8条回答
  •  时光说笑
    2020-12-01 12:05

    You should not put the windowManager.addView in onCreate

    Try to call the windowManager.addView after onWindowFocusChanged and the status of hasFoucus is true.

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        //code here
        //that you can add a flag that you can call windowManager.addView now.
    }
    

提交回复
热议问题