Androidアプリケーションを作成していますが、問題が発生しました。ImmutableMapオブジェクトの代わりにnullを取得しました。私の地図はガベージコレクションされているようです。しかし、私はそれへの参照を作成しました。これが私のすべてのソースコードで、コメントに問題の詳細な説明があります。
//I have a BaseActivity class in which i defined nested class
//which incapsulates some REST operations
public class BaseActivity extends Activity
{
//Here is this ImmutableMap to which I want save the result
private ImmutableMap<String, Object> serverData_;
//Here is this nested class which is AsyncTask
class RestfulNetworkTasks extends AsyncTask
<Pair<String,LinkedHashMap<String, Object>>, Void, LinkedHashMap<String, Object>>
{
NetworkOperation LowLevelRestOperations_ = new NetworkOperation();
@Override
protected LinkedHashMap<String, Object> doInBackground(Pair<String,LinkedHashMap<String, Object>>... params)
{
return LowLevelRestOperations_.executeServerCommand
(params[0].getValue0(), params[0].getValue1());
}
protected void onPostExecute(LinkedHashMap<String, Object> result)
{
//Here i created a reference to the result(in order
//to save it in my data structure)
serverData_ = copyOf(result);
UpdateCurrentActivityAfterNetworkOperation();
//Here I made a test output to check if i got the result
//All is good - I got a correct result saved to serverData_
android.util.Log.d("TEST RESPONSE", "ON POST" + serverData_);
}
}//End of nested class declaration
//Here is my method in which i want to call AsyncTask and got a problem
public void Login(LinkedHashMap<String,Object> parameters)
{
//Here I create an instance of that nested AsyncTask class
RestfulNetworkTasks serverOperation_ = new RestfulNetworkTasks();
Pair<String, LinkedHashMap<String, Object>> params_ =
new Pair<String,LinkedHashMap<String,Object>>(LOGIN_COMMAND, parameters);
//Here I call AsyncTask operation - i got a correct ON POST output
//with correct data
serverOperation_.execute(params_);
//But from this point my serverData_ is null!
//And I got null in AFTER POST output!Why?serverData_ is a member of BaseActivity so
//it have to keep the result.
android.util.Log.d("TEST RESPONSE", "AFTER POST" + serverData_);
}
では、これを修正する方法は?executeを呼び出した後にserverData_がnullになるのはなぜですか?
私は本当に助けが必要です-私はJavaとAndroidに本当に慣れていないので、この問題は私を夢中にさせました。前もって感謝します。