あなたが言おうとしていることを私が理解しているなら、はい、ハンドラーを使用して問題を解決する方法があります。
非同期タスクで、次のようにします-
private mLocations;
public MyTask(Handler mResponseHandler, List<Location> mLocations){
super();
this.mLocations = mLocations;
this.mResponseHandler = mResponseHandler;
}
onPostExecuteで、
onPostExecute(List<Location>){
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
Log.i(TAG, "result = "+result);
if (mResponseHandler == null) return;
MyLocationData<Location> resultData = new MyLocationData<Location>();
if(result != null && result){
resultData.requestSuccessful = true;
resultData.responseErrorCode = 0;
}else{
resultData.requestSuccessful = false;
resultData.responseErrorCode = errorCode; //set this when result is null
}
android.os.Message m = android.os.Message.obtain();
m.obj = resultData;
mResponseHandler.sendMessage(m);
}
}
MyLocationData は、関連するすべてのデータを保存するモデル クラスです。このようなクラスになることができます -
public class MyLocationData<Type> {
public Type response;
public int responseErrorCode;
public boolean requestSuccessful;
}
アクティビティで、次のようなデータを取得できます。
private Handler mExportHandler = new Handler(){
public void handleMessage(android.os.Message msg) {
MyLocationData<Location> responseData = (MyLocationData<Location>) msg.obj;
// your logic for fetching new locations from responseData and using them in your activity
};
};