java - 用户通过身份验证后,活动多次启动
问题描述
第二个活动在用户成功通过身份验证后启动多次。我在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 只启动一次?你也能解释一下为什么会这样吗?
解决方案
推荐阅读
- python - 在查找三个数字中最大的python代码中找不到实际问题
- javascript - 使用 Java 进行 RSA 加密,使用 JavaScript 进行解密
- monitoring - Prometheus 使用自定义标头抓取 /metric
- objective-c++ - 在 Objective-c++ 中,有没有办法将静态 c 函数移动到另一个文件?
- reactjs - 如何从外部 JavaScript 文件调用反应函数
- c# - 从 C# 使用 cmd 提示符过程时记住工作目录
- actions-on-google - Actions on Google:混合智能家居动作和会话动作
- java - 使用 REST 调用更新 S3 存储桶属性文件时更新所有 AWS 应用程序实例 java 属性对象
- swift - SecureCoding with Subclasses 和 CoreData ni swift
- firebase - 检查文档是否存在,如果不存在,则创建并添加数据 Firebase