Instead of using AsyncTask<String, Object, Object>
you can use AsyncTask<URI, Object, Object>
. Which will change your doInBackground(String... args)
to doInBackground(URI... args)
. This will require that you use URIs instead of Strings for all file paths.
If you were to use the non-generic AsyncTask class then you must use the doInBackground(Object... args)
method (not type safe).
However, using the generic AsyncTask<Params, Progress, Result>
class allows you to specify the type parameters. Params
correlates to the varargs Type in doInBackground(Params... args)
, Progress
correlates to the varargs type in protected void onProgressUpdate(Progress... args)
and Result
correlates to the return type of protected Result doInBackground
as well as the parameter type of protected void onPostExecute(Result arg)
.
In this case, it is best to use generic types as they are free of runtime errors (but not compile time). The same cannot be said for the non-generic AsyncTask that passes type Object references around.