Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am trying to inflate UI elements from service. But getting
WindowManager$InvalidDisplayException - the specified window type -1 is not valid
error.
My code is like below,
WindowManager windowManager = (WindowManager)getSystemService(WINDOW_SERVICE);
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.box, null);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
PixelFormat.TRANSLUCENT));
windowManager.addView(layout, params);
I am getting this error,
android.view.WindowManager$InvalidDisplayException: Unable to add window android.view.ViewRootImpl$W@8b06417 -- the specified window type -1 is not valid
at android.view.ViewRootImpl.setView(ViewRootImpl.java:725)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:94)
at com.firebaseapp.privacy.MyIntentService.handleAction(MyIntentService.java:33)
at com.firebaseapp.privacy.MyIntentService.onHandleIntent(MyIntentService.java:20)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:68)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.