context is getting exception in android 2.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 , 开发者_StackOverflow中文版it caught Exception: WindowManager$BadTockenException .
How can I specify 'context' in android 2.1 ?
Thank you....
Both ActivityGroup
and Activity
are Context
s, 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
.
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
精彩评论