Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:45:06+00:00 2026-05-23T21:45:06+00:00

In my service I add a view to WindowManager with addView() . When I’m

  • 0

In my service I add a view to WindowManager with addView(). When I’m ready to hide the view, I call removeView() using the View reference. This works great — most of the time.

I have occasional Force Close reports that say that the View is not attached to the WindowManager. This makes sense. The problem is that I think the service is getting killed by Android, and when it is time to hide the view, it attempts to removeView on the wrong View.

I have tried checking for the View to be null, but apparently it isn’t at this point, it simply isn’t the one attached to the WindowManager. It seems that if the View reference is lost, there is no way to gain access to it again.

How can I get the equivalent of findViewById() on the WindowManager itself? Is the View automatically removed from WindowManager if my service is stopped (killed)? Is there a way I can store the reference to the View so that if the service is stopped I can still remove the View later (I’m also trying to avoid leaking the View)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:45:07+00:00Added an answer on May 23, 2026 at 9:45 pm

    In my service I add a view to WindowManager with addView(). When I’m ready to hide the view, I call removeView() using the View reference. This works great–most of the time. I have occasional Force Close reports that say that the View is not attached to the WindowManager.

    I am having the exact same problem. Hopefully an expert will chime in.

    How can I get the equivalent of findViewById() on the WindowManager itself?

    Keep a reference to the View that was added and simply use removeView(mView).

    Currently in my Service, to add the view:

    WindowManager.LayoutParams params = ...
    mView = new View(this);
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(mView, params);
    

    Then to remove the view, I avoid occasional FC by catching the exception:

    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    try {
        wm.removeView(mView);
    } catch (Exception e) {}
    

    Is the View automatically removed from WindowManager if my service is stopped (killed)?

    In my experience, they are removed when the service is killed. You can test this by stopping your service without removing the views. No idea why that works though.

    My concern is that my second reference to the WM is different when I go to remove the view. If that is the case, is mView still being displayed when I catch the exception? I would try keeping a reference to the WM when I add the view, but I’ve had issues where references to System Services seem to go bad over time.

    Let me know if you ever solved this problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Add service reference to Amazon service fails, saying Could not load file or assembly
I've used Visual Studio's Add Service Reference feature to add a service (actually it
When I add a service reference to my Visual Studio 2010 C# project, a
What do I need to allow Visual Studio 2005 to add WCF service reference
I add a web reference to my wse 3.0 service in Visual Studio 2005
I have overlay View managed by WindowManager , just like in this question .
I used to be able to add a view using the Smart Client Factory
I customized a header view in a ListView by using xml file, this file
I know I can add service behaviors with some XML configuration, but I'd like
Let's say we have a service to add a new hotel: > POST /hotel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.