gpt4 book ai didi

java - 如何确定 setPersistenceEnabled 是否已启用?

转载 作者:行者123 更新时间:2023-12-02 12:37:11 24 4
gpt4 key购买 nike

一切正常。应用程序运行后,我通过多任务查看器按主页并返回到应用程序,它运行良好。但是,一旦它运行,并且我从抽屉中按下它的图标,它就会崩溃,因为它在运行时再次调用“setPersistenceEnabled()”。那么,在尝试启用它之前如何检查它是否已启用呢?我的代码:

public class SplashActivity extends AppCompatActivity {

private FirebaseUser firAuth;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getInstance().setPersistenceEnabled(true);


firAuth = FirebaseAuth.getInstance().getCurrentUser();

if (firAuth!=null) {
// User is signed in.
Intent intent = new Intent(this, Identificador.class);
startActivity(intent);
finish();

} else {
// No user is signed in.
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
finish();
}

};


}

最佳答案

我建议您使用以下代码行:

private static boolean calledAlready = false;
if (!calledAlready) {
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
calledAlready = true;
}

关于java - 如何确定 setPersistenceEnabled 是否已启用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45093332/

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