Android:在活动之间切换的时间很慢

时间:2016-02-27 09:52:14

标签: android android-intent

有没有办法加快换到其他活动的时间?或者我的代码有问题吗?

public void connectedAnim(){

    final Dialog dialog = new Dialog(LogIn.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.connected);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    IVcon = (ImageView)dialog.findViewById(R.id.IVcon);
    IVcon.setBackgroundResource(R.anim.connectedanim);

    final AnimationDrawable animcon = (AnimationDrawable)IVcon.getBackground();
    dialog.setCancelable(true);

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            animcon.start();
            Toast.makeText(getApplicationContext(), "Connected to HC-05", Toast.LENGTH_SHORT).show();
        }
    });
    dialog.show();

    new Handler().postDelayed(new Runnable() {
        public void run() {
            dialog.dismiss();
        }
    }, 1000);

    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            Intent Menu = new Intent(LogIn.this, Menu.class);
            LogIn.this.startActivity(Menu);
        }
    });

}

这是我将蓝牙连接到arduino时要调用的方法,并且我有一个动画,所以在动画结束后更改为新活动。这就是我所谓的connectedAnim()方法

pwordtxt.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable sa) {
        }

        @Override
        public void beforeTextChanged(CharSequence sa, int start,
                                      int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence sa, int start,
                                  int before, int count) {
            if (sa.length() == 4) {
                progressDialog = ProgressDialog.show(LogIn.this, "", "Loading..");
                password = getPass("password", getApplicationContext());
                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        if ((password.equals(""))) {
                            if (s.toString().equals("1234")) {

                                findBT();
                                try {
                                    openBT();
                                }
                                catch (IOException e) {}
                                beginListenForData();

                                handler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        progressDialog.dismiss();
                                        connectedAnim();
                                    }
                                });
                            } else {
                                Toast.makeText(LogIn.this, "Incorrect Password", Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            realpass = getPass("password", getApplicationContext());
                            if (s.toString().equals(realpass)) {
                                findBT();

                            } else {
                                Toast.makeText(LogIn.this, "Incorrect Password", Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                };
                new Thread(runnable).start();
            }
        }
    });
}

0 个答案:

没有答案