27

Вопрос по android, android-asynctask – Android вызывает AsyncTask сразу после завершения другого

Error: User Rate Limit Exceeded AsyncTask() authTask = new AsyncTask() { @Override protected JSONObject doInBackground(String... params) { //call the rest api } @Override protected void ...

Error: User Rate Limit Exceeded

от hcpeter

Error: User Rate Limit Exceeded<code>doInBackground</code>Error: User Rate Limit Exceeded<code>AsyncTask</code>Error: User Rate Limit Exceeded

от Jens

Error: User Rate Limit Exceeded

от Renard

7 ответов

1

int count;

 private void attemptConnect() 
 {
   count = 0;
   str_lang = "English";
   str_wait = "Plaese Wait";

   new AllQuestion().execute();

}


private class AllQuestion extends AsyncTask<String, String, String> {
    ProgressDialog pg;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        pg = new ProgressDialog(LanguageActivity.this);
        pg.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pg.setMessage(str_wait);
        pg.setCancelable(false);
        pg.show();
    }

    @Override
    protected String doInBackground(String... strings) {
        try {
            SoapObject soapObject = new SoapObject(AppConstant.NAMESPACE, AppConstant.QUESTION_SOAP_METHOD); 
            soapObject.addProperty("language", str_lang);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(soapObject);

            HttpTransportSE se = new HttpTransportSE(AppConstant.webUrl);
            se.call(AppConstant.QUESTION_SOAP_ACTION, envelope);


            Object responce = envelope.getResponse();
            Log.d("Question List:=>>", "" + responce);

            return responce.toString();
        } catch (Exception e) {
            e.printStackTrace();
            pg.dismiss();
            return null;
        }
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);

        if (pg.isShowing()) {
            pg.dismiss();
            Log.i(TAG, s);

            if (s != null || !s.equalsIgnoreCase("")) {
                try {
                    JSONArray array = new JSONArray(s);

                    for (int i = 0; i < array.length(); i++) {
                        JSONObject obj = array.getJSONObject(i);

                        String queId = obj.getString(TAG_QID);
                        String que = obj.getString(TAG_QUE);
                        String str_Opt = obj.getString(TAG_OPT);

                        question = new Question(queId, que, str_lang, str_catId, str_Opt, manager.getDateTime());
                        helper.insertQuestion(question);
                    }
                    count++;
                    if (count < 5) {
                        if (count == 1) {
                            str_lang = "German";
                            str_wait = "bitte warte einen Moment";

                                new AllQuestion().execute();
                        }
                        if (count == 2) {
                            str_lang = "Italian";
                            str_wait = "per favore aspetta un momento";

                                new AllQuestion().execute();
                        }
                        if (count == 3) {
                            str_lang = "Chinese";
                            str_wait = "请稍候";

                                new AllQuestion().execute();
                        }
                        if (count == 4) {
                            str_lang = "French";
                            str_wait = "patientez s'il-vous-plait";

                                new AllQuestion().execute();

                    }
                    Log.d("All Question:-", question.toString());

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
1

Error: User Rate Limit ExceededdoInBackgroundError: User Rate Limit Exceeded

26

Error: User Rate Limit ExceededgetStatus()Error: User Rate Limit ExceededAsyncTaskError: User Rate Limit Exceeded

if(authTask .getStatus() == AsyncTask.Status.PENDING){
    // My AsyncTask has not started yet
}

if(authTask .getStatus() == AsyncTask.Status.RUNNING){
    // My AsyncTask is currently doing work in doInBackground()
}

if(authTask .getStatus() == AsyncTask.Status.FINISHED){
    // START NEW TASK HERE
}

Error: User Rate Limit Exceeded

btn.setOnClickListener(new View.OnClickListener()
  {
    public void onClick(View v)
      {
        if (authTask != null && authTask.getStatus() == AsyncTask.Status.FINISHED) {
           //START YOUR NEW TASK HERE
        }
        else
        {
          //IGNORE BUTTON CLICK
        }
      }
   }); 
0

Error: User Rate Limit Exceededin just one async task:

protected Boolean doInBackground(String... params) {
            if(params[0] == "taskA") {
              //do somthing
              params[0] = "taskB";
            }
            if(params[0] == "taskB") {
              //do somthing
              params[0] = "taskC";
            }
            if(params[0] == "taskC") {
              //do somthing
              params[0] = "taskD";
            }
            if(params[0] == "taskD") {
              //do somthing
              return true;
            }

Error: User Rate Limit Exceeded

ShowMyProgress(); //if you like
new MyAsyncTask().execute("taskA");

Error: User Rate Limit Exceeded

protected void onPostExecute(final Boolean success) {
        if (success) {
            ....

            HideMyProgress();
        }
}
21

1:

Error: User Rate Limit ExceededdoInBackground()Error: User Rate Limit Exceededexecute()Error: User Rate Limit Exceeded


2:

Error: User Rate Limit Exceeded1Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceededexecute()Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

authTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
// Image task will only be done AFTER textViewTask is done
imageTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);

Error: User Rate Limit Exceeded

...
// ICS+ and pre honeycomb (I think)
authTask.execute();
// Image task will only be done AFTER textViewTask is done
imageTask.execute();
...

Error: User Rate Limit ExceededAsycnTask.execute() documentation:

Note: this function schedules the task on a queue for a single background thread or pool of threads depending on the platform version. When first introduced, AsyncTasks were executed serially on a single background thread. Starting with DONUT, this was changed to a pool of threads allowing multiple tasks to operate in parallel. After HONEYCOMB, it is planned to change this back to a single thread to avoid common application errors caused by parallel execution.


Error: User Rate Limit ExceededAsyncTask.THREAD_POOL_EXECUTORError: User Rate Limit Exceeded

// Go parallel! (NOT what you want)
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
4

Error: User Rate Limit ExceededdoInBackgroundError: User Rate Limit Exceeded

0

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededObservableIntegerError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

private ObservableInteger mObsInt;

Error: User Rate Limit Exceeded

//Listener
        mObsInt = new ObservableInteger();
        mObsInt.set(0);

        mObsInt.setOnIntegerChangeListener(new OnIntegerChangeListener()
        {
            @Override
            public void onIntegerChanged(int newValue)
            {
                if (mObsInt.get()==1)
                   //Do something if the first asyncTask finishes
                if (mObsInt.get()==2){
                   //Do something if the second asyncTask finishes, in this case i just go to another activity when both asyncTasks finish
                    Intent mainIntent = new Intent().setClass(LoginActivity.this, Principal.class);
                    startActivity(mainIntent);
                    finish();
                }
            }
        });

Error: User Rate Limit Exceeded

ObservableIntegerError: User Rate Limit ExceededmObsIntError: User Rate Limit ExceededmObsIntError: User Rate Limit ExceededasynctasksError: User Rate Limit ExceededasynctasksError: User Rate Limit ExceededmObsIntError: User Rate Limit ExceededasyncTaskError: User Rate Limit ExceededmObsIntError: User Rate Limit ExceededmObsInt++Error: User Rate Limit ExceededmObsIntError: User Rate Limit ExceededonCreateError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

mObsInt.set(mObsInt.get()+1);

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Похожие вопросы