1

IntentService を使用して、Web サイトからデータを取得し、データを解析し、結果に基づいてカレンダー イベントを作成するバックグラウンド タスクを実行するアプリケーションがあります。ローテーションで問題が発生していることを除いて、すべてが正常に作成されているようです。以下のコードを使用して、画面を回転すると、ProgressDialog ボックスは表示されたままになりますが、プロセスが更新されたときに新しいテキストで更新されることはなく、呼び出しが完了すると消えることはありません。私は ASyncTask の代わりに IntentService を使用しています。これは、ユーザーがアプリとやり取りすることなく、他の時間に IntentService を実行するようにスケジュールすることもできるためです。どんな助けでも大歓迎です、ありがとう!

public void onCreate(Bundle savedInstanceState) {
    Object retained = getLastNonConfigurationInstance();
    if (retained instanceof CalendarHandler) {
        // CH is a class level variable defined at the top which references my IntentService, aptly named CalendarHandler
        ch = (CalendarHandler) retained;
        ch.setActivity(this);
    } else {
        ch = null;
    }
    activity = this;

    btnLogin.setOnClickListener(OnClickListener(View view) {
            ch = new CalendarHandler();
            ch.setActivity(MyTlc.this);
            // Do other stuff, like run the intent service
    }
}

public Handler handler = new Handler() {
    public void handleMessage(Message message) {
        // We read the information from the message and do something with it
        // based on what the result code is
        String result = message.getData().getString("status");
        if (result.equals("ERROR")) {
            activity.removeDialog(PROGRESS_DIALOG);
            results.setText(message.getData().getString("error"));
        } else if (result.equals("DONE")) {
            activity.removeDialog(PROGRESS_DIALOG);
            int count = message.getData().getInt("count", 0);
            activity.results.setText("Added " + count + " shifts to the calendar");
        } else {
            activity.pDialog.setMessage(result);
        }
        super.handleMessage(message);
    }
};

私が理解していることから、これは機能するはずです.ProgressDialogボックスが適切に維持されると言ったように、回転後にダイアログボックスに情報を渡すことができないようです.

4

0 に答える 0