UIとは異なるスレッド(Runnableを実装する)にAndroidのアプリがあります
私はいくつかのデータ (緯度と経度の形式の 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
……代わりに「これ」でやってみたけど同じ話……
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 のコンテキストを含めるには?