0

I would like to ask, how to use and intent values from AsyncTask.

This is on the top: (This is the values which I would like to use)

Double confidence;
String plateNumberTest;

This is the actual AsyncTask

AsyncTask.execute(new Runnable() {
                @Override
                public void run() {
                    String result = OpenALPR.Factory.create(Index.this, ANDROID_DATA_DIR).recognizeWithCountryRegionNConfig("eu", "", destination.getAbsolutePath(), openAlprConfFile, 10);

                    Log.d("OPEN ALPR", result);

                    try {
                        final Results results = new Gson().fromJson(result, Results.class);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (results == null || results.getResults() == null || results.getResults().size() == 0) {
                                    Toast.makeText(Index.this, R.string.NotDetectToast, Toast.LENGTH_LONG).show();
                                    resultTextView.setText(R.string.NotDetect);
                                } else {
                                    resultTextView.setText(String.format("Plate: %s Confidence: %s%% Processing time: %s seconds", results.getResults().get(0).getPlate(), String.format("%.2f", results.getResults().get(0).getConfidence()), String.format("%.2f", ((results.getProcessing_time_ms() / 1000.0) % 60))));

                                    editText = (EditText) findViewById(R.id.edit_text);
                                    editText.setText(results.getResults().get(0).getPlate(), TextView.BufferType.EDITABLE);

                                    confidence = results.getResults().get(0).getConfidence();
                                    plateNumberTest = results.getResults().get(0).getPlate();

                                }
                            }


                        });

I was trying as I demonstrate in my example, by it's return as null

This is my intent, which is on setOnClickListener for button:

Intent intent = new Intent(Index.this, DVLAresult.class);
                Bundle extras = new Bundle();

                extras.putString("confidenceResult", String.valueOf(confidence));
                extras.putString("plateNumberResult", plateNumberTest);

                intent.putExtras(extras);

                startActivity(intent);

P.S. Sorry is this question in duplicated somewhere, but I can't figure it out with my example.

  • http://stackoverflow.com/questions/9118015/how-to-correctly-start-activity-from-postexecute-in-android this example is better – vinay Maneti Apr 19 '16 at 03:15
  • @vinay Maneti this is AsyncTask.execute(new Runnable(), still can't figure out how to do it. –  Apr 19 '16 at 03:20

0 Answers0