2つのアクティビティがあります。1つはエントリを表示するためのもので、もう1つはエントリを作成するためのものです。標準的な使用例は次のとおりです。
- ユーザーがアプリを開くと、エントリが表示されます。
 - ユーザーがボタンをクリックして新しいエントリを作成すると、新しいアクティビティが開きます。
 - ユーザーはエントリの作成を終了し、[完了]をクリックします。
 - アクティビティはsetResult()とfinish()で終了します。
 
追加したいのは、表示アクティビティが完全にロードされた後に実行されるAsyncTaskです。このAsyncTaskは、実行中にダイアログを表示します。問題は、このコードを次のようにonActivityResult()に配置すると、次のようになります。
@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) {     
    super.onActivityResult(requestCode, resultCode, data); 
        switch(resultCode) { 
        case (Activity.RESULT_OK): {
            mEntryListFragment.updateContent();
            runAsyncTaskHere();
        }
    }
}
メインアクティビティに戻る前にAsyncTaskを実行し、ダイアログは表示されません。私にできることはありますか?
編集:これがAsyncTaskです。
public static class LogInTask extends AsyncTask<String, Void, Integer> {
    protected String username = "";
    protected String password = "";
    protected ProgressDialog dialog;
    protected boolean showDialogs;
    public LogInTask(boolean sd) {
        this.showDialogs = sd;
    }
    @Override
    protected void onPreExecute() {
        if (this.showDialogs) dialog = ProgressDialog.show(MainActivity.getContext(), null, "Logging in...");
    }
    @Override
    protected Integer doInBackground(String... login) {
        if (Config.DEBUG) Log.d(Config.APP_NAME, "in doInBackground() of LogInTask");
        HttpResponse response = null;
        String username = login[0];
        String password = login[1];
        try {
            HttpPost httpPost = new HttpPost(URL_BASE + URL_LOGIN);
            // main (JSON) login method
            JSONObject json = new JSONObject().put("user", 
                    new JSONObject()
                        .put("email", username)
                        .put("password", password)
                        .put("remember_me", Config.REMEMBER_LOGIN)
                    );
            this.username = username;
            this.password = password;
            StringEntity se = new StringEntity(json.toString());
            httpPost.setHeader("Accept", "application/json");
            httpPost.setHeader("Content-type", "application/json");
            httpPost.setEntity(se);
            response = httpclient.execute(httpPost);
            String responseEntity = EntityUtils.toString(response.getEntity());
            JSONObject result = new JSONObject(responseEntity);
            return result.getBoolean("success") ? 1 : KEY_ERROR; // Return 1 if successful and -1 if not
        } catch (UnknownHostException e) {
            e.printStackTrace();
            KEY_ERROR;
        } catch (Exception e) {
            e.printStackTrace();
            return KEY_ERROR;
        }
    }
    @Override
    protected void onPostExecute(Integer result) {
        if (this.showDialogs) {
            dialog.dismiss();
            String text = result == 1 ? "Login was successful." : "Login failed!";
            makeToast(text);
        }
    }
}
編集2:私はこれを試しました:
boolean needToUpdate = false;
@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) {     
    super.onActivityResult(requestCode, resultCode, data); 
    switch(resultCode) { 
        case (Activity.RESULT_OK): {
            mEntryListFragment.updateContent();
            needToUpdate = true;
        }
    }
}
@Override
public void onResume() {
    super.onResume();
    if (needToUpdate) {
        runAsyncTaskHere();
        mEntryListFragment.updateContent();
    }
    needToUpdate = false;
}
そしてそれは同じことをしました。
編集3:AndroidManifestの関連セクションは次のとおりです。
 <activity 
        android:name=".MainActivity" 
        android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".AddEntryActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:configChanges="orientation" />