首页 > 解决方案 > 用户通过身份验证后,活动多次启动

问题描述

第二个活动在用户成功通过身份验证后启动多次。我在Volley get-Request中调用了意图,该意图在Firebase 使用 Email 和 Password Request 登录的 on success 方法中更进一步。

我已尝试按照此处FLAG_ACTIVITY_REORDER_TO_FRONT的建议添加标志,但它仍会多次启动。

这是我认为可能出现错误的代码(这些只是代码的一部分,而不是整个代码)

auth.signInWithEmailAndPassword(u, p)
   addOnCompleteListener(Login.this, new OnCompleteListener<AuthResult>() {
   @Override
   public void onComplete(@NonNull Task<AuthResult> task) {
        if (task.isSuccessful()) {
                     getdata();
                      }
          }

public void getdata() 
  {
   JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,URL, null,
      new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

          //Getting data from response

          Intent intent = new Intent(Login.this,Activity2.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
          startActivity(intent);
          finish();
    }
  requestQueue.add(jsonObjectRequest);
    }

如何确保 Activity2 只启动一次?你也能解释一下为什么会这样吗?

标签: javaandroidfirebasefirebase-authentication

解决方案


推荐阅读