Android: AsyncTask

1

In an AsyncTask you can put a condition where depends on the data you get perform the corresponding functions? Example, I have an AsyncTask that from the beginning sent an array but now I want to modify that AsyncTask but not only could the class that used the array be able to use it, now I want it to be occupied by another class and depending on what is ordered what corresponds to you.

I clarify that the AsyncTask I have it separately in a class.

In a class I send the AsyncTask a JSONObject

new UploadImage().execute(jsonObject);

From another class I send the AsyncTask a Bitmaps ArrayLIst

new UploadImage().execute(listOfBitmaps);

But as valid in that AsycTack what they send me because everyone does different things but I just want to occupy that AsycTask so I do not have to create another one

@Override
protected Void doInBackground(Object... params) {//ejecuta nuestras tareas principales

}
    
asked by Javier fr 17.12.2016 в 18:02
source

1 answer

2

No, you can not the input parameter is the one that corresponds. If you define that you are going to receive an arrangement, you must send an arrangement that can not be dynamic, for that you should do 2 different classes and before calling them identify what type of data you have to know what to call.

EDIT

Also (I can not test this now) you can receive a Object and within your method doInBackground identify the instance with instance of

    
answered by 17.12.2016 в 18:26