Getting context in a class that implements Runnable

I have an application in android that is in a different thread from the user interface (which implements Runnable)

I get some data (GPS data in the form of latitude and longitude), and from this data I

I want to find out the correct address by passing it to the geocoder ..... after that the address returned by Geocoder, I store it in the database:

Here is how I do it:

public class Client implemets Runnable{


public void run()
{

Geocoder myLocation=new Geocoder(getApllicationContext,Locale.getDefault());



}

}

but here I get the error:

Geocoder myLocation=new Geocoder(getApplicationContext,Locale.getDefault());

Runnable does not know who getApplicationContextis ..... I tried instead of "this", but the same story .....

Now, what is the right context for moving to the Geocoder constructor?

Here's what the Geocoder constructor looks like:

Geocoder myLocation =new Geocoder(context,locale);

In my activity I do this:

public class Server2 extends Activity {


public void onCreate(Bundle icicle) {


ClientThread_special client = new ClientThread_special(db);//here is where I start thread


        new Thread(client).start();
}


}

public class ClientThread_special implements Runnable {



 public ClientThread_special(DBAdapter db){

     this.db=db;
    }


 public void run() 

{

Geocoder myLocation=new Geocoder(getApllicationContext,Locale.getDefault());


}


}

How do I change the constructor

public ClientThread_special(DBAdapter db){

     this.db=db;

    }

to have a Server2 context in my Runnable?

+5
2

, ClientThreadSpecial ( )? , ?

, . , ClientThreadSpecial MyActivity ( Activity), - :

Geocoder myLocation=new Geocoder(MyActivity.this,Locale.getDefault());
+10

this, this Runnable. Runnable MyActivity ( Activity/Service), MyActivity.this.

+3

All Articles