私は位置情報サービスを作成しており、位置更新をサーバーに送信するための更新間隔があります。 しかし、この入力変数をユーザー入力(AlertDialog
)で更新しようとしました。ハードコーディングされたときは完璧に動作します。位置情報サービスの更新間隔Android
このコードを使用して、サービスのonCreate()
のAlertDialog
クラスから間隔変数を取得しています。
public void onCreate() {
super.onCreate();
final boolean tr=true;
new Thread(new Runnable() {
public void run() {
while (tr) {
//check your static variable here
updateInterval=ShowCurInterval.loadCurInterval(getApplicationContext());//ShowCur Interval is the Alert Dialog calss
Log.d(" INTERVAL ","Interval "+ updateInterval);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}}
).start();
startLocationListener(updateInterval);
}
そして、私はまた、(警告ダイアログから追加された)ログに新しいupdateInterval値を見ることができます。しかし、requestLocationUpdates()
はまだ定義済みのupdateInterval値を使用します。ここで
はstartLocationListener()メソッドです:
public void startLocationListener(int updateInterval) {
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locManager.removeUpdates(locListener);
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, updateInterval, updateDistance, locListener);
Log.d(getClass().getSimpleName(), "Loclistener started, Updatetime: " + updateInterval);
Toast.makeText(getApplicationContext(), "UPDATE INTERVAL"+updateInterval,Toast.LENGTH_SHORT);
preInterval = updateInterval;
}
誰もが、私は、この変数を更新することができますどのように任意の提案を持っていますか?
@binW例外 編集部分:
Handler mhandler = new Handler();
mhandler.postDelayed(new Runnable(){
public void run(){
Looper.prepare();
updateInterval=SingletonManager.getInstance().loadCurInterval(getApplicationContext());
SingletonManager.getInstance().saveCurInterval(getApplicationContext(), updateInterval);
startLocationListener(updateInterval);
Log.d(" INTERVAL ","Interval "+ updateInterval);
//startChecking();
}
}, 2000);
例外:
04-17 03:18:55.250: E/AndroidRuntime(2146): java.lang.RuntimeException: Only one Looper may be created per thread
は、事前にありがとうございました。
何が起こっているのですか?以前の更新レートでのみ動作していますか? – 5hssba
@rajuこんにちは..はい、以前の更新レートでのみ機能します。 updateIntervalは、10000(ミリ秒)の値を持つグローバル変数です。 – crtn