views:

254

answers:

2

Hi,

i would like to know if it's possible check connectivity in android without having a Context, because the thread i have running in background doesn't know the context. if there's no way, is a best practice passing to the thread the context?

thanks

+1  A: 

Yes, you need the Context. Possibly, your thread will already have access to a Context, courtesy of the Runnable it uses being an inner class of the Activity or Service that forked the thread.

CommonsWare
i need to check the connectivity from the object runnable, i don't know the thread neither
xger86x
A: 

Your runnable Object will run inside Activity or Service so it will have access to its methods

I think you can simply do:

OuterClassName.this.getContext();
skyman
no because the runnable object is defined in an other java file, it's not an inner class
xger86x