还记得我在启动画面中的功能吗?

时间:2016-03-01 01:27:31

标签: java android

因此,当我打开应用程序时,我想启动一个活动(启动画面)并显示它5秒钟。在这5秒钟内,我可以检查用户是否选中了“记住我”CheckBox(在SharedPreferences值中保存CheckBox的状态),如果他们这样做,则调用我的服务器并使用以前的电子邮件和密码(保存在SharedPreferences文件中) )签署并加载BuyerHomePage活动,如果没有,那么我希望他们转到SignInOrSignUp活动。

到目前为止,一切正常,但我永远陷入了闪屏。

这是我的代码

public class SplashScreen extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_splash_screen);

            RememberMe();

        }


        public void Delay(final boolean RememberMe) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (RememberMe == true) {
                        startActivity(new Intent(getApplicationContext(), BuyerHomePage.class));
                    } else {
                        startActivity(new Intent(getApplicationContext(), SignInOrSignUp_Activity.class));

                    }
                    SplashScreen.this.finish();
                }
            }, 5000);
        }

        public void RememberMe() {
            SharedPreferences RememberMeState = getSharedPreferences("RememberMeState", MODE_PRIVATE);
            boolean RememberMe;
            if (RememberMeState.getBoolean("Check", true)) {
                RememberMe = true;
            } else {
                RememberMe = false;
            }

            if (RememberMe == true) {
                SharedPreferences UserCredentials = getSharedPreferences("UserCredentials", MODE_PRIVATE);
                String RememberEmail = UserCredentials.getString("UserEmail", "");
                String RememberPassword = UserCredentials.getString("UserPassword", "");

                RememberMeLogIng(RememberEmail, RememberPassword);
            } else {
                Delay(RememberMe);
            }
        }


        public void RememberMeLogIng(String RememberEmail, String RememberPassword) {
            String method = "RememberLogin";
            BackgroundTask backgroundTask = new BackgroundTask(this);
            backgroundTask.execute(method, RememberEmail, RememberPassword);


        }
    }

1 个答案:

答案 0 :(得分:1)

你应该先叫完。

public  void Delay(final boolean RememberMe){
new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        SplashScreen.this.finish();
        if(RememberMe == true) {
            startActivity(new Intent(getApplicationContext(), BuyerHomePage.class));
        }else{
            startActivity(new Intent(getApplicationContext(), SignInOrSignUp_Activity.class));
        }            
    }
  }, 5000);
}

我这样写了你的方法。如果这不起作用,你可能也应该发布你的AsyncTask类。

public void RememberMe(){
    SharedPreferences RememberMeState = getSharedPreferences("RememberMeState",MODE_PRIVATE);
    boolean RememberMe = RememberMeState.getBoolean("Check", false);
    if(RememberMe){
        SharedPreferences UserCredentials = getSharedPreferences("UserCredentials",MODE_PRIVATE);
        String RememberEmail = UserCredentials.getString("UserEmail", "");
        String RememberPassword = UserCredentials.getString("UserPassword", "");

        RememberMeLogIng(RememberEmail, RememberPassword);
    }
    else{
        Intent loginIntent = new Intent(SplashScreen.this, LoginACtivity.class);
        startActivity(loginIntent);
    }
}