gpt4 book ai didi

java - 登录后触发欢迎屏幕 2-3 秒

转载 作者:行者123 更新时间:2023-12-02 04:52:39 25 4
gpt4 key购买 nike

我创建了一个登录屏幕并将我的API与其连接,并且电子邮件和密码的身份验证工作完美。我现在想做的是:1) 用户点击登录并成功后,会显示一个屏幕,显示“欢迎”,并在 2-3 秒后关闭,用户再次返回主屏幕。2) 如果用户再次启动该应用程序,则不会出现欢迎屏幕。它仅在您登录时出现,无论是第一次登录还是现有用户,但仅在按下登录按钮时出现。我是 android 的新手,所以我将一步一步进行。所以我创建了主屏幕。使用 API,这就是我现在正在尝试的。

谁能帮我解决一下吗?我正在使用 Retrofit 库。

登录 Activity

public class LoginScreen extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.loginBtnLogin).setOnClickListener(this);
findViewById(R.id.btn_createAccount).setOnClickListener(this);
private void userLogin(){
String Loginemail = loginEmail.getEditText().getText().toString().trim();
String Loginpassword = loginPassword.getEditText().getText().toString().trim();
Call<LoginResponse> call = RetrofitClient
.getInstance().getApi().userLogin(Loginemail, Loginpassword);

call.enqueue(new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
LoginResponse loginResponse = response.body();
if (loginResponse.getObj() != null){
Toast.makeText(LoginScreen.this, "Welcome", Toast.LENGTH_SHORT).show();
Intent intentLogin = new Intent(LoginScreen.this, HomeScreen.class);
startActivity(intentLogin);
}else{
Toast.makeText(LoginScreen.this, "Please Enter A Valid Email", Toast.LENGTH_SHORT).show();
}
}

@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {

}
});
}


@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.loginBtnLogin:
userLogin();
break;
case R.id.btn_createAccount:
Intent intentRegister = new Intent(LoginScreen.this, CreateAccount.class);
startActivity(intentRegister);
break;
}

}
}

改造客户端

public class RetrofitClient {
private static final String BASE_URL = "http://example.com/api/";
private static RetrofitClient mInstance;
private Retrofit retrofit;

private RetrofitClient() {

retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static synchronized RetrofitClient getInstance() {
if (mInstance == null) {
mInstance = new RetrofitClient();
}
return mInstance;
}

public LoginInterface getApi() {
return retrofit.create(LoginInterface.class);
}
}

InterfaceApi 是完全正确的,登录响应文件也是如此(通过在 android studio 中从 json 插件转换 pojo 来制作它们)

最佳答案

“在登录按钮上单击 putt 检查用户登录是否成功启动启动屏幕 2-3 秒,然后从启动屏幕移至主屏幕”

  new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashScreen.this,
yourHomeActivity.class));
finish();
}
}
},3000);

“此代码将显示欢迎屏幕三秒钟,然后它将移至主屏幕”

“希望你能找到解决方案”

关于java - 登录后触发欢迎屏幕 2-3 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56425585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com