0
我需要在通過WiFi Direct發送文件後關閉連接。我將管理器和通道傳遞給AsyncTask(它處理套接字Socket)並在doInBackground()的末尾調用cancelConnect()。它無法關閉連接,但是當我在MainActivity中調用cancelConnect()時,它工作正常。這是爲什麼?cancelConnect()在AsyncTask中不起作用
package com.ex.bb;
public class SocketAsync extends AsyncTask<Wrapper,Object,Object> {
private Context context;
// private TextView statusText;
public SocketAsync(Context context) {
this.context = context;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
protected String doInBackground(Wrapper...w) {
//File Sending Code
w[0].manager.cancelConnect(w[0].channel,new ActionListener(){
@Override
public void onSuccess() {
Log.i(MainActivity.TAG, "Disconnected from device");
}
@Override
public void onFailure(int reason) {
Log.i(MainActivity.TAG, "Couldn't disconnect from device");
}
});
}
包裝類由經理和渠道組成。
試過。沒有工作。 –