Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass a primitive int to my AsyncTask?

What I want it's to pass one int variable to my AsyncTask.

int position = 5;

And I declared my AsyncTask like this:

class proveAsync extends AsyncTask<int, Integer, Void> {

    protected void onPreExecute(){
    }

    protected Void doInBackground(int... position) {
    }

    .
    .
    .

But I got an error that it's the following:

Type argument cannot be of primitive type

I just could pass an int[] and Integer variables but never an int variable and I execute my AsyncTask like this:

new proveAsync().execute(position);

Is there something that I could do to pass only this position?

Thanks in advance!

like image 738
Francisco Romero Avatar asked Aug 18 '15 10:08

Francisco Romero


1 Answers

Pass your parameter as Integer

class proveAsync extends AsyncTask<Integer, Integer, Void> {

    protected void onPreExecute(){
    }

    protected Void doInBackground(Integer... position) {
        int post = position[0].intValue();
    }

    .
    .
    .

while executing do this

new proveAsync().execute(new Integer(position));

You can get the int value in AsyncTask as using intValue()

like image 168
Rohit5k2 Avatar answered Sep 24 '22 18:09

Rohit5k2