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

发布于 2024-11-04 02:18:05 字数 6819 浏览 2 评论 0原文

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

为此,我查看是否是第一次身份验证,并对应于我放置好的 xml 的答案。当我只用进度条显示 xml 时,我使用 asyncTask 连接到服务器,并加载我需要的内容。

这在模拟器上完美运行,但是当我将应用程序放在我的 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 吗?

I've a problem with asyncTask. In my app the user must log on. He do it one times, and I saved the login/pwd. When He launch the app for the second times, Instead of display the screen with login and pwd editText, I want to display another xml where there is a progressBar.

To do that, I look at if it's a first authentication or not, and corresponding to the answer I put the good xml. When I just display the xml with the progressBar, I do the connection to the server with an asyncTask, and load what I need.

That works perfectly on emulator, but when I put the app on m'y Nexus S (Android 2.3.3) that doesn't work, I've just a white screen, and nothing append.

The code of my activity :

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);
        }
    }

}

Please help me, I try many method, nothing works, and I given up hope of doing what I want

I just found a device with android 2.1, and it works fine. So there is something that is not compatible with android 2.3 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文