Android开发:AsyncTask中的progressdialog,但应用程序仍然崩溃

时间:2013-01-07 00:39:08

标签: android crash android-asynctask progressdialog

package com.whatstherex.sam;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class Login extends Activity {
String emailAdd;
EditText lEmail, lPassword, rUsername, rPassword, rRpassword, rEmail,
        rPhoneNum, rBirthday, rGender;
Button lLogin, rRegister;
TextView lAuth, rAuth;
AlertDialog loginDialog, registerDialog;
LinearLayout Llayout, Rlayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    setContentView(R.layout.login);

    initialize();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

public void initialize() {
    TabHost tabH = (TabHost) findViewById(R.id.tabhost);
    tabH.setup();
    TabSpec specs = tabH.newTabSpec("tag1");
    specs.setContent(R.id.Login);
    specs.setIndicator("Login");
    tabH.addTab(specs);
    TabSpec specs1 = tabH.newTabSpec("tag2");
    specs1.setContent(R.id.Register);
    specs1.setIndicator("Register");
    tabH.addTab(specs1);

    lEmail = (EditText) findViewById(R.id.etlEmail);
    lPassword = (EditText) findViewById(R.id.etlPassword);
    lLogin = (Button) findViewById(R.id.blLogin);
    lAuth = (TextView) findViewById(R.id.tvlAuth);

    rUsername = (EditText) findViewById(R.id.etrUsername);
    rPassword = (EditText) findViewById(R.id.etrpassword);
    rRpassword = (EditText) findViewById(R.id.etrRpassword);
    rEmail = (EditText) findViewById(R.id.etrEmail);
    rPhoneNum = (EditText) findViewById(R.id.etrPnumber);
    rBirthday = (EditText) findViewById(R.id.etrBirthday);
    rGender = (EditText) findViewById(R.id.etrGender);
    rRegister = (Button) findViewById(R.id.brRegister);
    rAuth = (TextView) findViewById(R.id.tvrAuth);

    hideKeyboardLayout(Llayout, R.id.Login);
    hideKeyboardLayout(Rlayout, R.id.Register);

    setLogin(lLogin);
    setRegister(rRegister);
}

public void hideKeyboardLayout(LinearLayout layout, int name) {
    layout = (LinearLayout) findViewById(name);

    layout.setOnTouchListener(new View.OnTouchListener() {

        protected void hideKeyboard(View v) {
            InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            in.hideSoftInputFromWindow(v.getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
        }

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            hideKeyboard(v);
            return false;
        }
    });
}

public void setLogin(Button b) {
    b.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub// TODO Auto-generated method stub
            new loadLogin().execute();
        }
    });
}

private void setRegister(Button b) {
    // TODO Auto-generated method stub
    b.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            registerDialog = new AlertDialog.Builder(Login.this).create();
            registerDialog.setTitle("Register Alert!");
            registerDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                    "Back", new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog,
                                int which) {
                            // TODO Auto-generated method stub
                            registerDialog.dismiss();
                        }
                    });

            ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
            postParameters.add(new BasicNameValuePair("usernamelog",
                    rUsername.getText().toString()));
            postParameters.add(new BasicNameValuePair("passwordlog",
                    rPassword.getText().toString()));
            postParameters.add(new BasicNameValuePair("rpasswordlog",
                    rRpassword.getText().toString()));
            postParameters.add(new BasicNameValuePair("emaillog", rEmail
                    .getText().toString()));
            postParameters.add(new BasicNameValuePair("phonenumlog",
                    rPhoneNum.getText().toString()));
            postParameters.add(new BasicNameValuePair("doblog", rBirthday
                    .getText().toString()));
            postParameters.add(new BasicNameValuePair("genderlog", rGender
                    .getText().toString()));

            String response = null;

            try {
                response = CustomHttpClient.executeHttpPost("http://whatstherex.info/CheckR.php", postParameters);

                String res = response.toString();

                res = res.replaceAll("null", "");

                if (res.equals("1")) {
                    rAuth.setText("Successfully Register");
                    rAuth.setTextColor(Color.GREEN);
                    registerDialog.setMessage("Successfully Register");
                    registerDialog.show();
                } else {
                    rAuth.setText(res.toString());
                    rAuth.setTextColor(Color.RED);
                    registerDialog.setMessage(res.toString());
                    registerDialog.show();
                }
            } catch (Exception e) {
                rAuth.setText(e.toString());
                rAuth.setTextColor(Color.BLACK);
            }
        }
    });
}

public class loadLogin extends AsyncTask<String, Void, String> {
    ProgressDialog dialog;

    protected void onPreExecute(){
    dialog = new ProgressDialog(Login.this, ProgressDialog.STYLE_SPINNER);
    dialog.setMessage("Loading Data...");
    dialog.show();
    }

    @Override
    protected String doInBackground(String... params) {
        loginDialog = new AlertDialog.Builder(Login.this).create();
        loginDialog.setTitle("Login Alert!");
        loginDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                loginDialog.dismiss();
                }
            });

        ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair("emaillog", lEmail.getText().toString()));
        postParameters.add(new BasicNameValuePair("passwordlog", lPassword.getText().toString()));

        String response = null;

        String res = "";
        try {
            response = CustomHttpClient.executeHttpPost( "http://whatstherex.info/checkL.php", postParameters);

            res = response.toString();

            res = res.replaceAll("null", "");

            if (res.equals("1")) {
                res = "Login Successfully!";
                lAuth.setTextColor(Color.GREEN);
                loginDialog.setMessage("Login Successfully!");
                loginDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Continue", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        new loadRedirect().execute();
                        }
                    });
                loginDialog.show();
                dialog.dismiss();
                return res;
            } else if (res.equals("0")) {
                res = "Sorry!! Incorrect Username or Password!";
                lAuth.setTextColor(Color.RED);
                loginDialog.setMessage("Sorry!! Incorrect Username or Password!");
                loginDialog.show();
                dialog.dismiss();
                return res;
            } else {
                res = res.toString();
                lAuth.setTextColor(Color.RED);
                loginDialog.setMessage(res.toString());
                loginDialog.show();
                dialog.dismiss();
                return res;
            }

        } catch (Exception e) {
            res = e.toString();
            lAuth.setTextColor(Color.BLACK);
    }
    return res;
}

protected void onProgressUpdate() {

}

protected void onPostExecute(String result){
    lAuth.setText(result);
    dialog.dismiss();
}

}

public class loadRedirect extends AsyncTask<String, Void, String> {
    ProgressDialog dialog;

    protected void onPreExecute(){
    dialog = new ProgressDialog(Login.this, ProgressDialog.STYLE_SPINNER);
    dialog.setMessage("Loading Data...");
    dialog.show();
    }

    @Override
    protected String doInBackground(String... params) {
        ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair("emaillog", lEmail.getText().toString()));
        postParameters.add(new BasicNameValuePair("passwordlog", lPassword.getText().toString()));

        String response = null;

        String res = "";
        try {
            response = CustomHttpClient.executeHttpPost("http://whatstherex.info/checkP.php", postParameters);

            res = response.toString();

            res = res.replaceAll("null", "");

            if (res.equals("1")) {
                Intent mainIntent = new Intent("com.whatstherex.sam.Main");
                mainIntent.putExtra("Email", lEmail.getText().toString());
                startActivity(mainIntent);
                dialog.dismiss();

            } else if (res.equals("0")) {
                Intent profilePicIntent = new Intent("com.whatstherex.sam.Profilepic");
                profilePicIntent.putExtra("Email", lEmail.getText().toString());
                startActivity(profilePicIntent);
                dialog.dismiss();
            } else {
                res = res.toString();
                lAuth.setTextColor(Color.RED);
                loginDialog.setMessage(res.toString());
                loginDialog.show();
                dialog.dismiss();
            }

        } catch (Exception e) {
            res = e.toString();
            lAuth.setTextColor(Color.BLACK);
            }
    return res;
}

protected void onProgressUpdate() {

}

protected void onPostExecute(String result){
    lAuth.setText(result);
    dialog.dismiss();
}

}

}

想要并且需要添加加载旋转的东西,否则ui将会挂起甚至可能崩溃。不确定我是否正确地将整个块分成2个AsyncTask。另外,为了刷新意图还有其他方式感谢finish();因为那会给黑屏。任何帮助将不胜感激。

这是日志文件:

01-07 08:58:44.984: D/dalvikvm(6078): Debugger has detached; object registry had 1 entries
01-07 08:58:45.355: D/AndroidRuntime(6090): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-07 08:58:45.355: D/AndroidRuntime(6090): CheckJNI is OFF
01-07 08:58:45.725: D/AndroidRuntime(6090): Calling main entry com.android.commands.am.Am
01-07 08:58:45.735: I/ActivityManager(1679): Force stopping package com.whatstherex.sam uid=10111
01-07 08:58:45.735: D/ViewRootImpl(1679): @@@- disable SystemServer HW acceleration
01-07 08:58:45.735: I/ActivityManager(1679): START intent from pid 6090
01-07 08:58:45.755: W/memalloc(1448): Falling back to ashmem
01-07 08:58:45.775: D/memalloc(1448): ashmem: Allocated buffer base:0x42542000 size:1536000 fd:47
01-07 08:58:45.775: D/memalloc(1679): ashmem: Mapped buffer base:0x55fb4000 size:1536000 fd:350
01-07 08:58:45.785: I/Adreno200-EGLSUB(1448): <CreateImage:893>: Android Image
01-07 08:58:45.785: I/Adreno200-EGLSUB(1448): <GetImageAttributes:1102>: RGBA_8888
01-07 08:58:45.795: D/CAT(1878): CatService: Return current sInstance
01-07 08:58:45.815: D/AndroidRuntime(6090): Shutting down VM
01-07 08:58:45.825: D/dalvikvm(6100): Late-enabling CheckJNI
01-07 08:58:45.825: I/AndroidRuntime(6090): NOTE: attach of thread 'Binder Thread #3' failed
01-07 08:58:45.825: D/dalvikvm(6090): GC_CONCURRENT freed 106K, 70% free 615K/2048K, paused 0ms+2ms
01-07 08:58:45.825: D/jdwp(6090): Got wake-up signal, bailing out of select
01-07 08:58:45.825: D/dalvikvm(6090): Debugger has detached; object registry had 1 entries
01-07 08:58:45.825: I/ActivityManager(1679): Start proc com.whatstherex.sam for activity com.whatstherex.sam/.Splash: pid=6100 uid=10111 gids={3003}
01-07 08:58:45.855: D/SensorManager(1679): [SensorManager] registerListener: delay = 200000
01-07 08:58:45.855: D/SensorService(1679): enable: get sensor name = BMA150 3-axis Accelerometer
01-07 08:58:45.855: D/Sensors(1679): Enable akm: en = 1
01-07 08:58:45.865: D/SensorService(1679): SensorDevice::activate--: handle = 0x0, enabled = 0x1
01-07 08:58:45.865: D/SensorService(1679): pid=1679, uid=1000
01-07 08:58:45.865: D/ConnectivityService(1679): onUidRulesChanged(uid=10111, uidRules=0)
01-07 08:58:45.875: D/AK8975(1458): Compass Start
01-07 08:58:45.875: V/WindowManager(1679): Starting animation in AppWindowToken{412e69f0 token=Token{412f5898 ActivityRecord{412f5648 com.htc.launcher/.Launcher}}} @ 160693935
01-07 08:58:45.875: V/WindowManager(1679): Finished animation in AppWindowToken{412e69f0 token=Token{412f5898 ActivityRecord{412f5648 com.htc.launcher/.Launcher}}} @ 160693935
01-07 08:58:45.885: V/WindowManager(1679): Starting animation in AppWindowToken{418942a0 token=Token{41836990 ActivityRecord{41836858 com.whatstherex.sam/.Splash}}} @ 160693935
01-07 08:58:45.895: W/ActivityThread(6100): Application com.whatstherex.sam is waiting for the debugger on port 8100...
01-07 08:58:45.905: I/System.out(6100): Sending WAIT chunk
01-07 08:58:45.925: I/dalvikvm(6100): Debugger is active
01-07 08:58:45.925: D/ViewRootImpl(1679): @@@- disable SystemServer HW acceleration
01-07 08:58:45.945: D/OpenGLRenderer(1794): Flushing caches (mode 1)
01-07 08:58:45.965: W/memalloc(1448): Falling back to ashmem
01-07 08:58:45.975: D/AK8975(1458): Ignore M_Sensor: (y, p, r) = ( 269,    5,    2), Status = 2
01-07 08:58:45.985: D/memalloc(1448): ashmem: Allocated buffer base:0x41c57000 size:737280 fd:48
01-07 08:58:46.025: D/memalloc(1679): ashmem: Mapped buffer base:0x5612b000 size:737280 fd:363
01-07 08:58:46.055: I/Adreno200-EGLSUB(1448): <CreateImage:893>: Android Image
01-07 08:58:46.055: I/Adreno200-EGLSUB(1448): <GetImageAttributes:1102>: RGBA_8888
01-07 08:58:46.095: W/dalvikvm(1794): disableGcForExternalAlloc: false
01-07 08:58:46.105: I/System.out(6100): Debugger has connected
01-07 08:58:46.105: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:46.306: V/WindowManager(1679): Finished animation in AppWindowToken{418942a0 token=Token{41836990 ActivityRecord{41836858 com.whatstherex.sam/.Splash}}} @ 160694367
01-07 08:58:46.316: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:46.336: D/AndroidRuntime(6116): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-07 08:58:46.336: D/AndroidRuntime(6116): CheckJNI is OFF
01-07 08:58:46.386: D/AndroidRuntime(6120): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-07 08:58:46.386: D/AndroidRuntime(6120): CheckJNI is OFF
01-07 08:58:46.516: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:46.596: D/memalloc(1448): ashmem: Freeing buffer base:0x421f5000 size:1536000 fd:103
01-07 08:58:46.596: D/memalloc(1448): ashmem: Freeing buffer base:0x42e1f000 size:1536000 fd:112
01-07 08:58:46.696: E/SurfaceTexture(1448): [SurfaceView] abandon: SurfaceTexture(0x0x6239e8) has been abandoned!
01-07 08:58:46.696: D/memalloc(1448): ashmem: Freeing buffer base:0x42042000 size:1536000 fd:37
01-07 08:58:46.716: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:46.736: D/OpenGLRenderer(1794): Flushing caches (mode 0)
01-07 08:58:46.916: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:46.936: D/memalloc(1448): ashmem: Freeing buffer base:0x42b6d000 size:1536000 fd:105
01-07 08:58:46.936: W/memalloc(1448): Falling back to ashmem
01-07 08:58:46.936: D/memalloc(1448): ashmem: Allocated buffer base:0x42042000 size:737280 fd:37
01-07 08:58:46.936: D/memalloc(1448): ashmem: Freeing buffer base:0x42fa7000 size:1536000 fd:113
01-07 08:58:46.946: D/memalloc(1679): ashmem: Mapped buffer base:0x561df000 size:737280 fd:366
01-07 08:58:46.946: I/Adreno200-EGLSUB(1448): <CreateImage:893>: Android Image
01-07 08:58:46.946: I/Adreno200-EGLSUB(1448): <GetImageAttributes:1102>: RGBA_8888
01-07 08:58:46.966: E/SurfaceTexture(1448): [com.htc.launcher/com.htc.launcher.Launcher] abandon: SurfaceTexture(0x0x62a9e0) has been abandoned!
01-07 08:58:46.996: D/memalloc(1448): ashmem: Freeing buffer base:0x41ecb000 size:1536000 fd:31
01-07 08:58:47.116: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:47.306: D/AndroidRuntime(6116): Calling main entry com.android.commands.am.Am
01-07 08:58:47.317: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:47.327: D/AndroidRuntime(6120): Calling main entry com.android.commands.am.Am
01-07 08:58:47.327: D/AndroidRuntime(6116): Shutting down VM
01-07 08:58:47.327: I/ActivityManager(1679): debugger status changed, pid: 6100, uid:10111, attach:true
01-07 08:58:47.347: I/AndroidRuntime(6116): NOTE: attach of thread 'Binder Thread #3' failed
01-07 08:58:47.347: D/dalvikvm(6116): GC_CONCURRENT freed 104K, 72% free 581K/2048K, paused 0ms+0ms
01-07 08:58:47.347: D/jdwp(6116): Got wake-up signal, bailing out of select
01-07 08:58:47.347: D/dalvikvm(6116): Debugger has detached; object registry had 1 entries
01-07 08:58:47.357: I/com.fd.httpd(26432): onStart
01-07 08:58:47.357: D/AndroidRuntime(6120): Shutting down VM
01-07 08:58:47.367: I/AndroidRuntime(6120): NOTE: attach of thread 'Binder Thread #3' failed
01-07 08:58:47.367: D/dalvikvm(6120): GC_CONCURRENT freed 106K, 71% free 613K/2048K, paused 1ms+1ms
01-07 08:58:47.367: D/jdwp(6120): Got wake-up signal, bailing out of select
01-07 08:58:47.367: D/dalvikvm(6120): Debugger has detached; object registry had 1 entries
01-07 08:58:47.517: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:47.717: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:47.917: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:48.117: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:48.317: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:48.518: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:48.718: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:48.878: D/PhoneStatusBarPolicy(1760): ServiceState ss: 0
01-07 08:58:48.888: D/PhoneStatusBarPolicy(1760): Network Type: 8
01-07 08:58:48.918: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:49.128: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:49.328: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:49.529: I/System.out(6100): waiting for debugger to settle...
01-07 08:58:49.729: I/System.out(6100): debugger has settled (1338)
01-07 08:58:49.979: D/libEGL(6100): loaded /system/lib/egl/libGLES_android.so
01-07 08:58:49.989: D/libEGL(6100): loaded /system/lib/egl/libEGL_adreno200.so
01-07 08:58:49.989: E/SurfaceTexture(1448): [Waiting For Debugger] abandon: SurfaceTexture(0x0x622fc8) has been abandoned!
01-07 08:58:49.989: D/memalloc(1448): ashmem: Freeing buffer base:0x41c57000 size:737280 fd:48
01-07 08:58:49.989: D/memalloc(1448): ashmem: Freeing buffer base:0x42042000 size:737280 fd:37
01-07 08:58:49.999: D/libEGL(6100): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
01-07 08:58:49.999: D/libEGL(6100): loaded /system/lib/egl/libGLESv2_adreno200.so
01-07 08:58:50.019: I/Adreno200-EGLSUB(6100): <ConfigWindowMatch:2078>: Format RGBA_8888.
01-07 08:58:50.019: W/memalloc(1448): Falling back to ashmem
01-07 08:58:50.029: D/memalloc(1448): ashmem: Allocated buffer base:0x41ecb000 size:1536000 fd:31
01-07 08:58:50.029: D/memalloc(6100): ashmem: Mapped buffer base:0x52287000 size:1536000 fd:62
01-07 08:58:50.039: D/OpenGLRenderer(6100): Enabling debug mode 0
01-07 08:58:50.049: W/InputManagerService(1679): Got RemoteException sending setActive(false) notification to pid 5529 uid 10111
01-07 08:58:50.049: I/InputManagerService(1679): [startInputLocked] Enable input method client.
01-07 08:58:50.099: W/memalloc(1448): Falling back to ashmem
01-07 08:58:50.119: D/memalloc(1448): ashmem: Allocated buffer base:0x42104000 size:1536000 fd:37
01-07 08:58:50.119: D/memalloc(6100): ashmem: Mapped buffer base:0x525b5000 size:1536000 fd:65
01-07 08:58:50.119: I/Adreno200-EGLSUB(1448): <CreateImage:893>: Android Image
01-07 08:58:50.119: I/Adreno200-EGLSUB(1448): <GetImageAttributes:1102>: RGBA_8888
01-07 08:58:50.119: I/ActivityManager(1679): Displayed com.whatstherex.sam/.Splash: +4s309ms
01-07 08:58:50.159: D/OpenGLRenderer(1794): Flushing caches (mode 2)
01-07 08:58:50.159: D/ConnectivityService(1679): onUidRulesChanged(uid=9999, uidRules=0)
01-07 08:58:50.319: E/SurfaceTexture(1448): [Starting com.whatstherex.sam] abandon: SurfaceTexture(0x0x626710) has been abandoned!
01-07 08:58:50.319: D/memalloc(1448): ashmem: Freeing buffer base:0x42542000 size:1536000 fd:47
01-07 08:58:50.620: V/WindowManager(1679): onProposedRotationChanged, rotation changed to 0
01-07 08:58:50.790: D/skia(1794): AndroidImageRef[ 0x135d460 ] releasePixel fail as lockCount=1
01-07 08:58:51.881: V/WindowManager(1679): onProposedRotationChanged, rotation changed to 0
01-07 08:58:51.881: D/AndroidRuntime(6145): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-07 08:58:51.881: D/AndroidRuntime(6145): CheckJNI is OFF
01-07 08:58:52.261: D/AndroidRuntime(6145): Calling main entry com.android.commands.am.Am
01-07 08:58:52.271: I/com.fd.httpd(26432): onStart
01-07 08:58:52.271: D/AndroidRuntime(6145): Shutting down VM
01-07 08:58:52.281: I/AndroidRuntime(6145): NOTE: attach of thread 'Binder Thread #3' failed
01-07 08:58:52.281: D/dalvikvm(6145): GC_CONCURRENT freed 106K, 71% free 613K/2048K, paused 0ms+0ms
01-07 08:58:52.281: D/jdwp(6145): Got wake-up signal, bailing out of select
01-07 08:58:52.281: D/dalvikvm(6145): Debugger has detached; object registry had 1 entries
01-07 08:58:54.924: I/ActivityManager(1679): START intent from pid 6100
01-07 08:58:55.444: I/Adreno200-EGLSUB(6100): <ConfigWindowMatch:2078>: Format RGBA_8888.
01-07 08:58:55.444: W/memalloc(1448): Falling back to ashmem
01-07 08:58:55.444: D/memalloc(1448): ashmem: Allocated buffer base:0x42542000 size:1536000 fd:47
01-07 08:58:55.454: D/memalloc(6100): ashmem: Mapped buffer base:0x5282c000 size:1536000 fd:72
01-07 08:58:55.545: W/SubtypeSwitcher(1863): Current subtype: en_US, keyboard
01-07 08:58:55.545: W/SubtypeSwitcher(1863): Last subtype was disabled. Update to the current one.
01-07 08:58:55.545: E/AbstractCompatWrapper(1863): Invalid input to AbstructCompatWrapper
01-07 08:58:55.545: E/CompatUtils(1863): Exception in invoke: NullPointerException
01-07 08:58:55.545: W/SubtypeSwitcher(1863): Update subtype to:en_US,keyboard, from: en_US, keyboard
01-07 08:58:55.545: D/SubtypeSwitcher(1863): Update shortcut IME from : com.google.android.voicesearch/.ime.VoiceInputMethodService, , voice
01-07 08:58:55.555: D/SubtypeSwitcher(1863): Update shortcut IME to : com.google.android.voicesearch/.ime.VoiceInputMethodService, , voice
01-07 08:58:55.555: I/HTCIMEService(1863): fetch result: 8.5
01-07 08:58:55.555: I/HTCIMEService(1863): fetch result: 8.5
01-07 08:58:55.585: I/XT9_C(1863): [loadDefaultDB] xt9_raw/ldb_0409.ldb size=304198 (loaded)
01-07 08:58:55.595: I/XT9_C(1863): [registerXT9LDB] ldb_0409.ldb loading [done]
01-07 08:58:55.595: D/XT9_C(1863): [registerXT9LDB] current LdbNum=109, First LdbNum=109, Second LdbNum=0
01-07 08:58:55.605: I/XT9_C(1863): [loadDefaultDB] xt9_raw/kbd_0d09.kbd size=20852 (loaded)
01-07 08:58:55.605: I/XT9IMEAutoComplete(1863): [hanldeDBContentSensitive]  set PDSwitch's OnDiagnoseListener for Email4PDSwitch
01-07 08:58:55.605: I/HTCIMMView(1863): [FixedWCL] adjustWCLHeight height:65
01-07 08:58:55.635: W/memalloc(1448): Falling back to ashmem
01-07 08:58:55.635: D/memalloc(1448): ashmem: Allocated buffer base:0x41c57000 size:860160 fd:64
01-07 08:58:55.635: D/memalloc(1863): ashmem: Mapped buffer base:0x527bb000 size:860160 fd:66
01-07 08:58:55.695: D/dalvikvm(1863): GC_FOR_ALLOC freed 720K, 29% free 7708K/10787K, paused 55ms
01-07 08:58:55.735: I/Adreno200-EGLSUB(1448): <CreateImage:893>: Android Image
01-07 08:58:55.735: I/Adreno200-EGLSUB(1448): <GetImageAttributes:1102>: RGBA_8888
01-07 08:58:55.755: D/OpenGLRenderer(6100): has fontRender patch
01-07 08:58:55.775: D/OpenGLRenderer(6100): has fontRender patch
01-07 08:58:55.825: D/OpenGLRenderer(6100): has fontRender patch
01-07 08:58:55.825: W/memalloc(1448): Falling back to ashmem
01-07 08:58:55.845: D/memalloc(1448): ashmem: Allocated buffer base:0x42b6d000 size:1536000 fd:67
01-07 08:58:55.845: D/memalloc(6100): ashmem: Mapped buffer base:0x52b29000 size:1536000 fd:75
01-07 08:58:55.845: I/Adreno200-EGLSUB(1448): <CreateImage:893>: Android Image
01-07 08:58:55.845: I/Adreno200-EGLSUB(1448): <GetImageAttributes:1102>: RGBA_8888
01-07 08:58:55.855: I/ActivityManager(1679): Displayed com.whatstherex.sam/.Login: +875ms
01-07 08:58:55.855: V/WindowManager(1679): Starting animation in AppWindowToken{418942a0 token=Token{41836990 ActivityRecord{41836858 com.whatstherex.sam/.Splash}}} @ 160703906
01-07 08:58:55.855: V/WindowManager(1679): Finished animation in AppWindowToken{418942a0 token=Token{41836990 ActivityRecord{41836858 com.whatstherex.sam/.Splash}}} @ 160703906
01-07 08:58:55.855: V/WindowManager(1679): Starting animation in AppWindowToken{41814af8 token=Token{417bfa58 ActivityRecord{417bf920 com.whatstherex.sam/.Login}}} @ 160703906
01-07 08:58:55.875: D/OpenGLRenderer(6100): Flushing caches (mode 0)
01-07 08:58:55.875: D/memalloc(1448): ashmem: Freeing buffer base:0x42104000 size:1536000 fd:37
01-07 08:58:55.885: E/SurfaceTexture(1448): [com.whatstherex.sam/com.whatstherex.sam.Splash] abandon: SurfaceTexture(0x0x6239e8) has been abandoned!
01-07 08:58:55.895: D/memalloc(1448): ashmem: Freeing buffer base:0x41ecb000 size:1536000 fd:31
01-07 08:58:56.065: W/memalloc(1448): Falling back to ashmem
01-07 08:58:56.075: V/WindowManager(1679): Finished animation in AppWindowToken{41814af8 token=Token{417bfa58 ActivityRecord{417bf920 com.whatstherex.sam/.Login}}} @ 160704136
01-07 08:58:56.085: D/memalloc(1448): ashmem: Allocated buffer base:0x41ecb000 size:1536000 fd:31
01-07 08:58:56.095: D/memalloc(6100): ashmem: Mapped buffer base:0x52287000 size:1536000 fd:63
01-07 08:58:56.095: I/Adreno200-EGLSUB(1448): <CreateImage:893>: Android Image
01-07 08:58:56.095: I/Adreno200-EGLSUB(1448): <GetImageAttributes:1102>: RGBA_8888
01-07 08:58:56.115: D/dalvikvm(1794): GC_BEFORE_OOM freed 150K, 51% free 7261K/14563K, paused 247ms
01-07 08:58:56.556: I/Adreno200-EGLSUB(1448): <CreateImage:893>: Android Image
01-07 08:58:56.556: I/Adreno200-EGLSUB(1448): <GetImageAttributes:1102>: RGBA_8888
01-07 08:58:56.876: D/AndroidRuntime(6159): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-07 08:58:56.876: D/AndroidRuntime(6159): CheckJNI is OFF
01-07 08:58:57.286: D/AndroidRuntime(6159): Calling main entry com.android.commands.am.Am
01-07 08:58:57.296: I/com.fd.httpd(26432): onStart
01-07 08:58:57.296: D/AndroidRuntime(6159): Shutting down VM
01-07 08:58:57.306: I/AndroidRuntime(6159): NOTE: attach of thread 'Binder Thread #3' failed
01-07 08:58:57.306: D/dalvikvm(6159): GC_CONCURRENT freed 106K, 71% free 613K/2048K, paused 0ms+0ms
01-07 08:58:57.306: D/jdwp(6159): Got wake-up signal, bailing out of select
01-07 08:58:57.306: D/dalvikvm(6159): Debugger has detached; object registry had 1 entries
01-07 08:58:57.877: D/PhoneStatusBarPolicy(1760): ServiceState ss: 0
01-07 08:58:57.877: D/PhoneStatusBarPolicy(1760): Network Type: 8
01-07 08:58:59.138: I/Adreno200-EGLSUB(6100): <ConfigWindowMatch:2078>: Format RGBA_8888.
01-07 08:58:59.148: W/memalloc(1448): Falling back to ashmem
01-07 08:58:59.148: D/memalloc(1448): ashmem: Allocated buffer base:0x419a8000 size:245760 fd:37
01-07 08:58:59.148: D/memalloc(6100): ashmem: Mapped buffer base:0x521a8000 size:245760 fd:61

我从调试中得到的错误是

Thread [<11> AsyncTask #1] (Suspended (exception RuntimeException)) 
    <VM does not provide monitor information>   
    ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1094  
    ThreadPoolExecutor$Worker.run() line: 569   
    Thread.run() line: 864  

2 个答案:

答案 0 :(得分:0)

您不能以任何方式从其他线程(不是UI线程)修改UI。因此,在AsyncTask.doInBackground方法中创建/显示/解除对话框是不正常的,并且您遇到了崩溃。

答案 1 :(得分:0)

不要在doInBackground上这样做,它不是UI线程。

loginDialog = new AlertDialog.Builder(Login.this).create();
loginDialog.setTitle("Login Alert!");
loginDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Back", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub
        loginDialog.dismiss();
    }
});

您可以将操作作为字符串返回,这就是您拥有此操作的原因:

protected String doInBackground(String... params)

如果你想解雇对话框,请在onPostExcecute()中传递并评估它(如果你在完成工作后没有评估任何内容,只需添加Void代替String)。如果要创建对话框,请在onPreExecute()上执行。它们都在UI线程上运行。

例如:

@Override
protected void onPreExecute() {
super.onPreExecute();
    progressDialog = new ProgressDialog(context);
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("Sending message....");
    progressDialog.show();
}

http://developer.android.com/reference/android/os/AsyncTask.html#onPostExecute(Result)