首页 > 解决方案 > 如何在改造中将用户重定向到他们的活动

问题描述

我有一个用户类型,即用户和主管..登录时我希望用户去使用健康数据活动和主管去仪表板活动。

这是我的登录代码。

公共无效登录用户(字符串电子邮件,字符串密码){

    Call<ResponseBody> call = RetrofitClient
            .getInstance()
            .getApi().login(email, password);

    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Authenticating please wait...");
    progressDialog.show();
    call.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

                Intent intent = new Intent(LoginActivity.this, UserHealthDataActivity.class);
                startActivity(intent);
                Toast.makeText(LoginActivity.this, "Login successfully!", Toast.LENGTH_SHORT).show();

                loginRequest = new LoginRequest(email, password);
                String loginRequestJson = gson.toJson(loginRequest);
                PH.get().setObjectAsJsonString(getApplicationContext(), "LOGGED_IN_USER", loginRequestJson); //save the login details to shared preference
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Toast.makeText(LoginActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
            System.out.println("throwing ..." + t);
            loadingBar.dismiss();
        }
    });
}

}

标签: javaandroidretrofit

解决方案


推荐阅读