1

I use android 2.2 for developing my application. But when I run it on 2.1 emulator, it caught ome exception.

Every exception is caught on 'Context'. Actaully I am using ActivityGroup in my application. And my activity is extending another class. So i use 'this.getParent()' in the field of 'Context'. This is working fine in android 2.2 and also on later version. I use getBaseConext() and getApplicationContext(). But the error is still remains there. The dialog is coming. But then suddently it caught exception.

For example :

 Dialog dateDialog = new Dialog(this.getParent());

But in android 2.1 , it caught Exception: WindowManager$BadTockenException .

How can I specify 'context' in android 2.1 ?

Thank you....

Jomia
  • 3,414
  • 10
  • 46
  • 63

2 Answers2

1

Both ActivityGroup and Activity are Contexts, and I'll bet you the Activity inherits the ActivityGroup's Context by default. In conclusion, try using this.

What you have described is very similar to a problem I had, which seemed to be a problem with launching dialogs from onCreate and using anything other than this as a Context.

Community
  • 1
  • 1
Felix
  • 88,392
  • 43
  • 149
  • 167
0

your activity group has activities in it, doesn't it?

what if you declare in each of inner activities context member (mContext) and initialize it with this in onCreate()? then you can call new Dialog(mContext)

UPD: i googled a bit because this problem could be interesting for me as well. And i've found this Link:

http://www.codingon24s.com/2011/02/dialogs-and-android-view-windowmanagerbadtokenexception-2/

But i haven't tried it

Tima
  • 12,765
  • 23
  • 82
  • 125
  • I tried what u suggested. But stiil getting the error : "android.view.WindowManager$BadTockenException : unable to add window -- token null is not for an application." – Jomia Feb 28 '11 at 12:00
  • Have you seen this link http://www.codingon24s.com/2011/02/dialogs-and-android-view-windowmanagerbadtokenexception-2/ ? – Tima Feb 28 '11 at 14:02