asyncTask的问题在模拟器上工作,而不在设备上工作

时间:2011-04-29 10:29:47

标签: android android-emulator device android-asynctask

我遇到了asyncTask的问题。在我的应用程序中,用户必须登录。他做了一次,我保存了登录/密码。当他第二次启动应用程序时,我想显示另一个有进度条的xml,而不是用login和pwd editText显示屏幕。

要做到这一点,我看看它是否是第一次认证,并且对应于我放好的xml的答案。当我只使用progressBar显示xml时,我使用asyncTask连接到服务器,并加载我需要的内容。

这在模拟器上完美运行,但是当我将应用程序放在m'y Nexus S(Android 2.3.3)上时,我只是一个白色屏幕,没有任何附加功能。

我的活动代码:

public class AuthentificationActivity extends Activity implements
        OnClickListener {

    private Button btnConnection;
    private EditText edtUserName;
    private EditText edtPassword;
    private TextView lblForgottenPass;
    private ProgressBar progressBar;
    private TextView txtProgression;
    private TextView txtAlerts;

    private EntirePersonBM entirePersonBM = new EntirePersonBM();

    private String uidh = new String();
    private String userName = new String();
    private String password = new String();
    private boolean isFirstConnection = true;
    public static boolean isFinishApp = false;

    private Selection selection;
    private SelectionResultSet resultSet;
    private SharedPreferences settings;
    private String alerts = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        settings = getSharedPreferences("login", 0);

        isFirstConnection = settings.getBoolean("isFirstConnection",
                        true);

        try {
            if (isFirstConnection) {

                // Put connection screen, and help
                this.setContentView(R.layout.login);
                btnConnection = (Button) findViewById(R.id.btnConnection);
                edtUserName = (EditText) findViewById(R.id.edtUserName);
                edtPassword = (EditText) findViewById(R.id.edtPassword);
                lblForgottenPass = (TextView) findViewById(R.id.lblForgottenPass);
                progressBar = (ProgressBar) findViewById(R.id.progressBar1);
                txtProgression = (TextView) findViewById(R.id.textView1);
                txtAlerts = (TextView) findViewById(R.id.txtAlerts);

                btnConnection.setOnClickListener(this);
                lblForgottenPass.setOnClickListener(this);
            } else {
                // Directly connect to server with saved login/pwd
                // Retrieve login/pwd
                this.setContentView(R.layout.splash_login);
                txtProgression = (TextView) findViewById(R.id.txtProgression);

                userName = settings.getString("currentUserName", null);
                password = settings.getString("currentPwd", null);
                new ConnectionTask().execute("");
                }
            }

        } catch (Exception e) {

            Alerts
                    .showAlert(getString(R.string.AlertsErrorOccured), this,
                            true);

        }

    }




    public void connect(SharedPreferences settings) {

        String login = settings.getString("currentUserName", null);
        String pwd = settings.getString("currentPwd", null);

        Log.v("Retrieve user", "Always log >>> Login = " + login);

        // call server
        AuthentificationServletCall auth = new AuthentificationServletCall();
        try {
            entirePersonBM = auth.Authentification("BoozterMobile", login, pwd,
                    "passwordHash");

            Log.v("call server", "Connecting >>> OK");
        } catch (Exception e) {
            Log.v("call server", "Connecting >>> ERROR :" + e);
            e.printStackTrace();
        }

    }

    public void loadMail() {

        selection = callsUtils.loadingSelection(UserControler.getInstance()
                .getUidh(), "NEW", null, String
                .valueOf(BoozterMobileConstants.MAX_VALUES_SUGGESTION), "desc");

        if (selection != null) {

            resultSet = callsUtils.loadingMailList(UserControler.getInstance()
                    .getUidh(), selection, String.valueOf(1));

        }
        if (selection != null && resultSet != null) {

            ListHeaderControler.getInstance().setFirstAuthentification(false);
            ListHeaderControler.getInstance().setRefresh(false);
            ListHeaderControler.getInstance().setSentMail(false);
            ListHeaderControler.getInstance().setSplashActivty(true);
            ListHeaderControler.getInstance().setSel(selection);
            ListHeaderControler.getInstance().setRs(resultSet);
            ListHeaderControler.getInstance().setMailHeaderList(
                    resultSet.getEuis());

        }

    }

    private class ConnectionTask extends AsyncTask<String, Void, Object> {
        protected Void doInBackground(String... args) {
            Log.v("AsyncTask", "Start connectionTask");
            connect(settings);
            return null;
        }

        protected void onPostExecute(Object result) {
            // Pass the result data back to the main activity
            txtProgression.setText(getString(R.string.lblGetBlock));
            new BlockLoaderTask().execute("");
        }
    }

    private class BlockLoaderTask extends AsyncTask<String, Void, Object> {
        protected Void doInBackground(String... args) {
            Log.v("AsyncTask", "Start BlockLoaderTask");

            BlockControler.getInstance().setListWhere(
                    BlocksUtils.generateList(String
                            .valueOf(BoozterMailConstants.BLOCK_CATEGORY_ID),
                            true, null));

            return null;
        }

        protected void onPostExecute(Object result) {
            // Pass the result data back to the main activity
            txtProgression.setText(getString(R.string.lblGetMails));
            new MailLoaderTask().execute("");
        }
    }

    private class MailLoaderTask extends AsyncTask<String, Void, Object> {
        protected Void doInBackground(String... args) {
            Log.v("AsyncTask", "Start BlockLoaderTask");

            loadMail();

            return null;
        }

        protected void onPostExecute(Object result) {

            // create Intent
            Intent defineIntent = new Intent(AuthentificationActivity.this,
                    HeaderMailDisplayActivity.class);

            // Object that allows to pass the mail's seqnums and person's uidh
            // onto headerMail activity
            Bundle objetbunble = new Bundle();
            objetbunble.putString("positionList", String.valueOf(1));
            defineIntent.putExtras(objetbunble);

            // call headerMail activity
            AuthentificationActivity.this.startActivity(defineIntent);
        }
    }

}

请帮助我,我尝试了很多方法,没有任何作用,我放弃了做我想做的希望

我刚刚发现了一个带有android 2.1的设备,它运行正常。那么有些东西与android 2.3不兼容?

0 个答案:

没有答案