如何在执行AsyncTask时处理Internet连接丢失

时间:2015-11-10 18:25:15

标签: android android-asynctask

我想在互联网连接丢失并向用户显示Toast时取消AsyncTask,我已经经历了许多类似的问题,但我不知道在哪里注册接收器并取消AsyncTask。

private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {

    @Override

    public void onReceive(Context context, Intent intent) {

        boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);

        String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);

                    boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);
        NetworkInfo currentNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

        NetworkInfo otherNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);



    }

};

0 个答案:

没有答案