私は、AsyncTaskを拡張するクラスを持っています。私はクラスBroadcast AsyncTaskからブロードキャストを送信できますか?
バックグラウンドタスクを実行すると、ポスト実行時に他のクラスの静的プロパティがバックグラウンドの結果と等しくなります。他のクラスの受信者が更新インターフェイス
になると、ブロードキャストしますここonPostExecuted
のコードprotected void onPostExecute(String result) {
Log.d(tag, "post executed "+result);
// do sth here
if (result != null){
result = result.trim();
String temp_result[];
if (result.contains("|")){
temp_result = result.split("\\|");
MyGPS.location_info = temp_result[1];//
Log.d(result, "contains | : "+MyGPS.location_info);
}else if (result.equalsIgnoreCase("300 OK")){
Log.d(result, "in 300 OK BUT UNKNOWN : "+ result);
MyGPS.location_info = "Unknown";
}else if (result.equalsIgnoreCase("400 ERROR"))
Log.d(result, "400 ERROR : "+ result);
else Log.d(result, "else : "+ result);
//assemble data bundle to be broadcasted
//myFilteredResponseThread = new Intent(GPS_FILTER);
myFilteredResponseThread.putExtra("location_info_post",
MyGPS.location_info);
// CAN"T USE SEND BROADCAST METHOD ?
//myFilteredResponseThread.
//Log.e(">>GPS_Service<<", "location_info"+MyGPS.location_info);
}
}
その後、私はsendBroadcastメソッドを記述することはできません、それはなぜ未定義のですか?
あなたはAsyncTaskを拡張し、このクラスに活動コンテキストを渡していないかもしれません。あなたがアクティビティコンテキストを渡している場合は、context.sendbroadcat(intent)を使用してください。 – Vivek
私の内部クラスのGPSListenerからこのスレッドAysnctTaskを呼び出すとLocationListenerが実装され、この内部クラスはクラス拡張サービスに含まれているので、どうすればAsyncTaskにコンテキストを渡すことができますか? Thx – sayvortana