我的android代码中有一个叫做选择设备的AsyncTask类,当主活动启动它会执行类但我需要在if用户改变手机的wifi连接时启动和停止。我可以这样做吗?
final selectingDevices select=new selectingDevices();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
select.execute();
}
private class selectingDevices extends AsyncTask{
@Override
protected Object doInBackground(Object[] params) {
if (!isCancelled())
{
startBonjour();
}
return null;
}
@Override
protected void onCancelled(){}
}