Android checks connection without context

I would like to know if it is possible to check the connectivity in android without Context, because the thread that is running in my background does not know the context. if there is no way, is it best practice to pass context to the thread?

thank

+3
source share
2 answers

Yes you need Context. Perhaps your thread will already have access to the Contextkindly provided Runnablethat it uses as an inner class Activityor Servicethat forked the thread.

+4
source

Your runnable Object will be launched inside an Activity or Service so that it has access to its methods.

, :

OuterClassName.this.getContext();
0

Source: https://habr.com/ru/post/1732919/


All Articles