Issue
This must be really easy but I am stuck now for an hour or so. I am passing String[]
to an AsyncTask
class as such
class test extends AsyncTask<String, Void, Void>{
@Override
protected Void doInBackground(String... params) {
// Again, use either params local to this function
// or args local to the entire function...
// both would be redundant
String _NAMESPACE = params[0];
String _METHODNAME = params[1];
String _SOAPACTION = params[2];
String _USER_NAME = params[3];
String _USER_PASS= params[4];
// Do background stuff
}
}
I am sending my arguments as such
test t = new test();
String[] s = {"a", "b", "c", "d", "e"};
t.execute(s);
This is not working. How would I pass multiple String
objects is my question. If I pass one string it works but if I try to pass them in an array it fails. btw I don't want to change the string parameter of the AsyncTask
class to String[]
because it would break my other code. Any help would be appreciated.
Solution
If you want to pass multiple Objects to this AsyncTask you can create a constructor to match them.
private class MyAsyncTask extends AsyncTask<Void, Void, Integer>
{
public AsyncFileExists(Integer num1, Integer num2, String s, Boolean b) {
super();
// Do something with these parameters
}
@Override
protected void onPreExecute() { }
@Override
protected Integer doInBackground(Void... params) {
...
And then just do
MyAsyncTask myTask = new MyAsyncTask(5, 10, "a string", false);
Answered By - Teo Inke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.