onProgressUpdate永远不会被调用

时间:2015-11-11 16:30:36

标签: android android-asynctask

我有AsyncTask,如下面的代码所示,但onProgressUpdate方法永远不会被调用

请让我知道为什么会这样。

注意:使用.executeOnExecutor

调用此asyncTask

    private class ATRx extends AsyncTask<Void, String, Void> {

    private int mWaitTime = getApplicationContext().getResources().getInteger(R.integer.int_max_wait_time);
    private int mSleepTime = getApplicationContext().getResources().getInteger(R.integer.int_sleep_time);

    private boolean mRequestSent = false;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Log.w(TAG, CSubTag.msg("ATRx.onPreExecute"));

        //mBtnConnect.setEnabled(false);
        mEtTxMsg.setVisibility(View.VISIBLE);
        mBtnSend.setVisibility(View.VISIBLE);
        mBtnDisconnect.setVisibility(View.VISIBLE);
    }

    @Override
    protected Void doInBackground(Void... params) {
        Log.w(TAG, CSubTag.msg("ATRx.doInBackground"));

        mSPP.tx("!DIRON<CR><LF>");
        int readBytes = mSPP.rx();
        publishProgress("any text");
        //mSPP.tx("!VERON");

        Log.d(TAG, CSubTag.subBullet("ATRx.doInBackground", "before while-loop readBytes: " + readBytes));

        while (!isCancelled() && readBytes != -1) {
            Log.d(TAG, CSubTag.subBullet("ATRx.doInBackground", "while-loop readBytes: " + readBytes));
            publishProgress(String.valueOf(readBytes));
            readBytes = mSPP.rx();
        }

        Log.d(TAG, CSubTag.subBullet("ATRx.doInBackground", "after while-loop readByte: " + readBytes));
        publishProgress(String.valueOf(readBytes));

        if (readBytes == -2) {
            Log.e(TAG, CSubTag.bullet("ATRx.doInBackground", ".rx(): end of stream has been reached"));
            //Log.d(TAG, CSubTag.bullet("ATRx.doInBackground", "iWait: " + iWait));
            return null;
        }
        if (readBytes == -1) {
            Log.e(TAG, CSubTag.bullet("ATRx.doInBackground", ".rx(): IO-Exception no data to read FRC-Socket is closed"));
            return null;
        }

        return null;
    }

    @Override
    protected void onProgressUpdate(String... values) {
        Log.w(TAG, CSubTag.msg("ATRx.onProgressUpdate"));
        super.onProgressUpdate(values);

        mTvRx.setText(values[0]);
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        Log.w(TAG, CSubTag.msg("ATRx.onPostExecute"));

        mSPP.closeInStream();
        mSPP.closeOutStream();
        mSPP.closeRFCSocket();
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
        Log.w(TAG, CSubTag.msg("ATRx.onCancelled"));

        mSPP.closeInStream();
        mSPP.closeOutStream();
        mSPP.closeRFCSocket();
    }
}

1 个答案:

答案 0 :(得分:0)

取出(...)电话

<string>(?<!\w)word=(?!\w)</string>
相关问题