0

I am new to android , some times my application works fine if i pass

If I use,

this for context // sometimes gets error  

If I use,

ClassName.this for context // sometimes gets error       

android.view.WindowManager$BadTokenException:
   Unable to add window -- token   
android.app.LocalActivityManager$LocalActivityRecord@40537450 is not valid; is your activity running?  

If I use,

getApplicationContext()

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

If I use,

ClassName.this.getParent()  

I am confused when to use what.

Please Explain

LMK
  • 2,882
  • 5
  • 28
  • 52
  • :D I think you are displaying a dialog.. which is not possible without activity context (in your words ClassName.this). So make sure your activity is running. Thats it. – Pankaj Kumar Aug 07 '13 at 11:03
  • What is your question/problem ? The errors you get are certainly not only related on which form of Context you're using. – Sw4Tish Aug 07 '13 at 11:04
  • @Sw4Tish in intent,Intent in = new Intent(packageContext, cls), for packageContext i can pass this,this.getParent(),getApplicationContext(). And in, TextView text = new TextView(context); i can pass this,getContext() – LMK Aug 07 '13 at 11:15
  • @PankajKumar yes i am displaying dialog,can you please explain more? – LMK Aug 07 '13 at 11:21
  • So you can not display dialog without Activity context. Read more http://stackoverflow.com/questions/7918571/how-to-display-a-dialog-from-a-service if you are trying to show dialog from Service/ Receiver – Pankaj Kumar Aug 07 '13 at 11:24
  • I am not really sure, but I think you can have more context in your app, so you max be using a bad one when you are getting these errors. You might want to study this... http://stackoverflow.com/questions/3572463/what-is-context-in-android – arenaq Aug 07 '13 at 11:07

0 Answers0