android http post asynctask

前端 未结 2 2066
萌比男神i
萌比男神i 2020-12-04 23:19

Please can anyone tell me how to make an http post to work in the background with AsyncTask and how to pass the parameters to the AsyncTask? All the examples that I found we

2条回答
  •  鱼传尺愫
    2020-12-04 23:56

    First i would not recommend do a Http request in a AsyncTask, you better try a Service instead. Going back to the issue on how to pass parameter into an AsyncTask when you declared it you can defined each Object class of the AsyncTask like this.

    public AsyncTask  {
    
    }
    

    so in your task you should go like this

    public MyTask extends{
    
    public Void doInBackground(String... params){//those Params are String because it's declared like that
    
    }
    
    }
    

    To use it, it's quite simple

    new MyTask().execute("param1","param2","param3")
    

提交回复
热议问题