0
E/AndroidRuntime(16172): FATAL EXCEPTION: main
E/AndroidRuntime(16172): java.lang.IllegalArgumentException: no dialog with id 2 was ever shown via Activity#showDialog
E/AndroidRuntime(16172):        at android.app.Activity.missingDialog(Activity.java:2600)
E/AndroidRuntime(16172):        at android.app.Activity.dismissDialog(Activity.java:2585)
E/AndroidRuntime(16172):        at com.proapps.eng.android.client.meeting_screen$1.handleMessage(meeting_screen.java:196)
E/AndroidRuntime(16172):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(16172):        at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(16172):        at android.app.ActivityThread.main(ActivityThread.java:3701)
E/AndroidRuntime(16172):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(16172):        at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(16172):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
E/AndroidRuntime(16172):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
E/AndroidRuntime(16172):        at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  238):   Force finishing activity com.proapps.eng.android.client/.MainScreenActivity
W/ActivityManager(  238): Activity pause timeout for HistoryRecord{2b54bd38 com.proapps.eng.android.client/.MainScreenActivity}

この例外はToast.show()の後にスローされ、その直後に、現在のfinish()ではなく新しいアクティビティ(メインアクティビティ)を開始します。

final Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        // Get the current value of the variable total from the message data
        // and update the progress bar.
        int total = msg.getData().getInt("total");
        progDialog.setProgress(total);
        if (total <= 0){
            dismissDialog(typeBar);
            progThread.setState(ProgressThread.DONE);
            mail_sent_popup.show(); // mail sent popup
            startActivity(new Intent(cntx,MainScreenActivity.class));      
        // start the main instead of finishing this one.
        }
    }
}; 

新しいアクティビティに渡すとき、ダイアログが前のアクティビティで導入されたことを「忘れます」。私は何をすべきか?

ところで、それは常にスローするわけではなく、時々だけです。ありがとう!!!

編集:(ダイアログスレッドの)もう少しコード

private class ProgressThread extends Thread {

    // Class constants defining state of the thread
    final static int DONE = 0;
    final static int RUNNING = 1;

    Handler mHandler;
    int mState;
    int total;


    EditText name_text = (EditText)findViewById(R.id.editText1);
    EditText phone_text = (EditText)findViewById(R.id.editText2);
    EditText free_text = (EditText)findViewById(R.id.editText3);

    // Constructor with an argument that specifies Handler on main thread
    // to which messages will be sent by this thread.

    ProgressThread(Handler h) {
        mHandler = h;
    }

    // Override the run() method that will be invoked automatically when 
    // the Thread starts.  Do the work required to update the progress bar on this
    // thread but send a message to the Handler on the main UI thread to actually
    // change the visual representation of the progress. In this example we count
    // the index total down to zero, so the horizontal progress bar will start full and
    // count down.

    @Override
    public void run() {
        mState = RUNNING;   
        total = maxBarValue;
        while (mState == RUNNING) {

                // LONG JOB HERE

                }

            Message msg = mHandler.obtainMessage();
            Bundle b = new Bundle();
            b.putInt("total", 0);
            msg.setData(b);
            mHandler.sendMessage(msg);

        }
    }

    // Set current state of thread (use state=ProgressThread.DONE to stop thread)
    public void setState(int state) {
        mState = state;
    }
}

dismissDialog(typeBar);だと思います。このスレッドを停止するための間違った方法です。コードのどこにstate=ProgressThread.DONEを入れるべきかわかりません

EDIT2:

ダイアログとアクティビティのonCreateの一部を宣言するコードを追加しました。

public void onCreate(Bundle savedInstanceState) {
    ...
    ...
    showDialog(2);
    ...
}


    @Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,mDay);
    case TIME_DIALOG_ID:
        return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute,false);
    case 2:
        progDialog = new ProgressDialog(this);
        progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progDialog.setMessage("Sending...");
        progThread = new ProgressThread(handler);
        progThread.start();
        return progDialog;
    }
    return null;
}
4

2 に答える 2

1

通常、ダイアログは単一のアクティビティによって所有されます。ActivityAでダイアログを表示してから、ActivityBでそれを閉じることはできません。

于 2012-05-30T15:20:55.410 に答える
0

これは私がこの問題を解決した方法です:

    final Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        // Get the current value of the variable total from the message data
        // and update the progress bar.
        int total = msg.getData().getInt("total");
        progDialog.setProgress(total);
        if (total <= 0){
            progThread.setState(ProgressThread.DONE);
//          dismissDialog(typeBar);     // PROBLEMATIC
            mail_sent_popup.show(); // mail sent popup
            startActivity(new Intent(cntx,MainScreenActivity.class));
// start the main instead of finishing this one.
        }
    }
};

手動のdismissDialogにコメントし、progThread.setState(ProgressThread.DONE);でスレッドを終了させます。これが誰かに役立つことを願っています。

于 2012-06-03T09:05:45.237 に答える