WindowManager$BadTokenException: Unable to add window -- token null is not for an application

7534 views
Skip to first unread message

Ash

unread,
Nov 26, 2008, 12:33:42 PM11/26/08
to Android Developers
Hello super smart people, I've got a strangle little bug to test you.

I have an application that tries to display an RTSP video in a view
(Content View -> ScrollView -> AbsoluteLayout -> VideoView). However,
in the emulator the MediaPlayer throws dispatches an error message
which tries to display an Alert which throws the WindowManager
exception. On device I hear the sound but do not see the the video
then I get the exception when the MediaController is shown. WTF is
going on? If I create a tiny Activity this works fine but once I get
into a "real" application it all goes to hell. Is this Dalvik and the
Android SDK showing it's immaturity?

Ash

Noam Wolf

unread,
Nov 27, 2008, 3:09:10 PM11/27/08
to Android Developers
Is this something new? I wasn't seeing this behavior before
yesterday's update. Any idea on how to get around it?

Noam Wolf

unread,
Nov 28, 2008, 2:43:49 PM11/28/08
to Android Developers
I think it existed before the update too. The way I get around it is
kind of stupid, right now i'm wrapping the call to "show" with a try/
catch. That way when the activity is running/alive it will work,
otherwise it will die quietly.

Dianne Hackborn

unread,
Nov 30, 2008, 12:23:26 AM11/30/08
to android-d...@googlegroups.com
It would help if you would include the stack crawl of the error and such.

One cause of this error may be trying to display an application window/dialog through a Context that is not an Activity.
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support.  All such questions should be posted on public forums, where I and others can see and answer them.

Ash

unread,
Dec 10, 2008, 2:28:21 PM12/10/08
to Android Developers
It seems that my problem was due to using
Activity.getApplicationContext as the context.

On Nov 29, 9:23 pm, "Dianne Hackborn" <hack...@android.com> wrote:
> It would help if you would include the stack crawl of the error and such.
>
> One cause of this error may be trying to display an application
> window/dialog through a Context that is not an Activity.
>
>
>
> On Wed, Nov 26, 2008 at 9:33 AM, Ash <ashleym...@yahoo.com> wrote:
>
> > Hello super smart people, I've got a strangle little bug to test you.
>
> > I have an application that tries to display an RTSP video in a view
> > (Content View -> ScrollView -> AbsoluteLayout -> VideoView). However,
> > in the emulator the MediaPlayer throws dispatches an error message
> > which tries to display an Alert which throws the WindowManager
> > exception. On device I hear the sound but do not see the the video
> > then I get the exception when the MediaController is shown. WTF is
> > going on? If I create a tiny Activity this works fine but once I get
> > into a "real" application it all goes to hell. Is this Dalvik and the
> > Android SDK showing it's immaturity?
>
> > Ash
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
Reply all
Reply to author
Forward
0 new messages