How to stop HttpURLConnection connect on Android

前端 未结 2 2023
我寻月下人不归
我寻月下人不归 2020-12-01 15:07

I use AsyncTask to connect an URLPath as below code.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
           


        
2条回答
  •  情歌与酒
    2020-12-01 15:24

    Save the HttpURLConnection response by (HttpURLConnection)url.openConnection(); as a class member: HttpURLConnection mHttpURLConnection = (HttpURLConnection)url.openConnection();

    after you call future.cancel(true); then call mHttpURLConnection.disconnect()

    so the network request will end as fast as possible

提交回复
热议问题