Android 4.0`Android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)上的异常`

Android 4.0`Android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)上的异常`,android,android-4.0-ice-cream-sandwich,android-networking,Android,Android 4.0 Ice Cream Sandwich,Android Networking,当我在安卓2.3.6上运行这段代码时,它运行得很好。在4.0上,我得到一个StrictMode异常。从一些问题来看,似乎你不能在UI线程上进行网络操作。但是我没有在UI线程上执行任何UI操作 我直接调用doBackground而不是execute,因为我需要检查doBackground的返回值。我想下面的方法应该有用 我错过了什么 handler.postDelayed(new Runnable() { @Override public void run() { God.identity

当我在安卓2.3.6上运行这段代码时,它运行得很好。在4.0上,我得到一个StrictMode异常。从一些问题来看,似乎你不能在UI线程上进行网络操作。但是我没有在UI线程上执行任何UI操作

我直接调用doBackground而不是execute,因为我需要检查doBackground的返回值。我想下面的方法应该有用

我错过了什么

handler.postDelayed(new Runnable() {
@Override
public void run() {
    God.identityHash = (String) new SwitchServer((IActionBar) splashScreen,
                God.mCruiseOnServer, nameText, phoneNumberText)
                .doInBackground(null);

    if (!mIsBackButtonPressed && God.identityHash != null) {
        FlurryAgent.logEvent(God.TCACCEPTED_AND_REGISTERED);
        Intent intent = new Intent(SplashScreen.this, HomeScreen.class);
        SplashScreen.this.startActivity(intent);
        finish();
    } else {
        Toast.makeText(splashScreen,
            "Unable to save your details. Please try again.",
            Toast.LENGTH_LONG).show();
        God.setTermsAndConditions(splashScreen, false);
    }
}
}, SPLASH_DURATION); 
编辑:手机上未启用严格模式。

首先,是从代码中显式打开的,它只是一种调试辅助,不应在生产代码中保持打开状态


其次,手动调用
.doInBackground
意味着在UI线程上运行它。如果按预期使用,则会在
中获取其返回值作为参数。onPostExecute

AsyncTask
还是其他什么,我真的不明白您在这里想做什么是的,我没有在其“正常”中使用AsyncTask在这一点上。我建议您使用AsyncTask来实现您想要的目标。我在处理程序可运行的、愚蠢的问题中调用doInBackground,但这不会使doInBackground脱离UI线程吗?不,消息处理程序运行它(尽管延迟),这意味着UI线程。