我在 android 中有一个应用程序,它位于与 UI 不同的线程中(实现 Runnable)
我收到一些数据(经纬度形式的 GPS 数据)并从这些数据中我
想通过将其传递给地理编码器来找出正确的地址.....在地理编码器返回的地址之后,我将其存储在数据库中:
以下是我如何做这些事情:
public class Client implemets Runnable{
public void run()
{
Geocoder myLocation=new Geocoder(getApllicationContext,Locale.getDefault());
}
}
但我在这里收到错误:
Geocoder myLocation=new Geocoder(getApplicationContext,Locale.getDefault());
Runnable 不知道getApplicationContext
是谁......我尝试用“this”代替,但同样的故事......
现在哪个是传递给 Geocoder 构造函数的正确上下文????
以下是 Geocoder 构造函数的样子:
Geocoder myLocation =new Geocoder(context,locale);
在我的活动中,我这样做:
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());
}
}
我应该如何修改构造函数
public ClientThread_special(DBAdapter db){
this.db=db;
}
为了在我的 Runnable 中有 Server2 的上下文?