第二活动在用户成功通过身份验证后多次启动。我在 Volley get-Request 中调用了该意图,该意图在使用电子邮件和密码请求登录的Firebase成功方法中更进一步。
我尝试按照建议的here添加标志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仅启动一次?您还能解释为什么会这样吗?