0

I have a function which takes some time to execute. currently Im running it inside a Thread, because i cant make the AsyncTask working. i need to pass a double[] variable as input to doInBackground, then it should return the result which is also a double[] variable to onPostExecute where the result will be printed in a textView.
it looks this simple:

public class finder extends AsyncTask <Double , Void , Double> {
    double[] input;
    double[] result;

    public finder() {
        super();
    }


    @Override
    protected double[] doInBackground(Double... params) {

        result = foo(input)

        return result;
    }


    protected void onPostExecute(Double... params) {


    }

public double[] foo (double [] input){...}
}

so i have a few questions:

1- What configuration of arguments for the Class and each method could do the job?
2-Do i need to override the methods? (when i change the doInBackground specifier to double[] it gives me an error on @Override)
3- what should be each methods specifier?
4- how could i make onPostExecute recognize the textView? what shoud be passed to the asyncTask ?

2 Answers2

0

Your question has been answered at the link below. I think it will help you. Thanks What arguments are passed into AsyncTask<arg1, arg2, arg3>?

TIenHT
  • 61
  • 1
  • 7
  • i've read the documentation and everything would be easy if the input was a list or just a double variable. but the input array that i have, is an array whose elements should be given to `foo(double[])` all at once. and the result array must be returned from `doInBack` , so `doInBack` must be declared as double[] which gives me an error. – amin tahertalari Feb 10 '20 at 12:12
0

well it seems like creating a class with only two double[] members and passing the class as AsyncTask argument and return type of doInBackground would resolve the problem.

class mTest {

     double[] testresult;
     double [] testinput;


}

and:

private class myAsync extends AsyncTask<mTest, Void , mTest>{


        mTest localmtest = new mTest();

        @Override
        protected mTest doInBackground(mTest...pp) {
            localmtest = pp[0];
            localmtest.testresult = foo(localmtest.testinput);

            return localmtest;
        }

        @Override
        protected void onPostExecute(mTest ppp) {

            outputset(ppp.testresult);
            //outputset sets some TextView text

        }


    }

Thanks to @Tien hT for their help.