T
T
titovnikita2014-04-19 16:22:11
Android
titovnikita, 2014-04-19 16:22:11

How to pass data to AsyncTask Android?

Hello, I'm trying to send a message to AsyncTask, which stores the Bitmap. But for some reason null comes in AsyncTask. Please tell me what I'm doing wrong. Thanks in advance.

private synchronized void runRecognition(Message message){
        
        new RecognizeAsyncTack().execute(message);
      }
     
     private final class RecognizeAsyncTack extends AsyncTask<Message, Void, OcrDB>{

       @Override
      protected void onPreExecute() {

        super.onPreExecute();
        isRecognizing = true;
      }
       
      @Override
      protected OcrDB doInBackground(Message... params) {
        
        Message message = params[0];
        return decodeByteMessage((Bitmap) message.obj, message.arg1, message.arg2);
      }
      
      @Override
      protected void onPostExecute(OcrDB result) {
        super.onPostExecute(result);
        activity.setOcrResult(result);
        isRecognizing = false;
      }
       
     }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
titovnikita, 2014-04-19
@titovnikita

I solved the problem by replacing the object of type Message with my own class. Apparently something with Handler'om. Thanks

N
nonrblGyN4ik, 2014-04-19
@nonrblGyN4ik

I tried debugging or logging, maybe you are losing it somewhere, so it comes as null?
Stuff checks and output to the logs, before each use, if you haven’t done so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question