我在我的新Android应用中实施Firebase电子邮件/密码身份验证。
该应用程序在大多数情况下都可以正常工作,除了当用户点击登录或注册的两个按钮之一时,应用程序会跳过所谓的活动,登录或注册,然后直接进入mainActivity。
这就是我写下打开下一个活动的意图: -
mRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ChooseLogin.this, RegistrationActivity.class);
startActivity(intent);
finish();
return;}});
我在调试中发现了两个可能相关的错误: -
W / zygote64:由于无法识别而跳过重复的类检查 classloader W / DynamiteModule:本地模块描述符类 找不到com.google.firebase.auth。
以及: -
W / DynamiteModule:本地模块描述符类 找不到com.google.android.gms.crash。
根据我的类似问题的答案:
与firebase助手核对,它说我已经连接了。
检查在firebase控制台中我已启用电子邮件/密码登录
检查了我的设备和模拟器,并且两者都采取了相同的行动
选中我使用最新的com.google.firebase:firebase-auth:11.6.0'
检查了google play服务是否合适' classpath' com.google.gms:google-services:3.1.0'
甚至添加到联盟许可的清单请求中
实施了firebases crashylytics并且它没有抓住这个
重新添加google.services.json文件,然后构建/重建项目
编辑(根据要求提供registrationActivity和logcat):
registrationActivity' onCreate:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance();
fireBaseStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Intent intent = new Intent(RegistrationActivity.this, MainActivity.class);
startActivity(intent);
finish();
return;}};
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(fireBaseStateListener);
}
Logcat:
11-23 11:58:59.652 12880-12880/com.sanruza.alpak.tinderlike I/zygote64: Late-enabling -Xcheck:jni
11-23 11:59:00.016 12880-12880/com.sanruza.alpak.tinderlike W/zygote64: Skipping duplicate class check due to unrecognized classloader
11-23 11:59:00.020 12880-12880/com.sanruza.alpak.tinderlike W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-23 11:59:00.027 12880-12880/com.sanruza.alpak.tinderlike W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-23 11:59:00.048 12880-12880/com.sanruza.alpak.tinderlike I/BiChannelGoogleApi: [FirebaseAuth: ] No Fallback module; NOT setting up for lazy initialization
11-23 11:59:00.091 12880-12914/com.sanruza.alpak.tinderlike W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
11-23 11:59:00.104 12880-12914/com.sanruza.alpak.tinderlike I/FirebaseAuth: [FirebaseAuth:] Loading module via FirebaseOptions.
11-23 11:59:00.104 12880-12914/com.sanruza.alpak.tinderlike I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
11-23 11:59:00.118 12880-12917/com.sanruza.alpak.tinderlike I/DynamiteModule: Considering local module com.google.android.gms.flags:2 and remote module com.google.android.gms.flags:0
11-23 11:59:00.118 12880-12917/com.sanruza.alpak.tinderlike I/DynamiteModule: Selected local version of com.google.android.gms.flags
11-23 11:59:00.148 12880-12917/com.sanruza.alpak.tinderlike W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.
11-23 11:59:00.156 12880-12917/com.sanruza.alpak.tinderlike I/DynamiteModule: Considering local module com.google.android.gms.crash:0 and remote module com.google.android.gms.crash:10
11-23 11:59:00.157 12880-12917/com.sanruza.alpak.tinderlike I/DynamiteModule: Selected remote version of com.google.android.gms.crash, version >= 10
11-23 11:59:00.162 12880-12880/com.sanruza.alpak.tinderlike V/FA: Cancelling job. JobID: -385218149
11-23 11:59:00.171 12880-12880/com.sanruza.alpak.tinderlike V/FA: Registered activity lifecycle callback
11-23 11:59:00.172 12880-12880/com.sanruza.alpak.tinderlike I/FirebaseInitProvider: FirebaseApp initialization successful
11-23 11:59:00.205 12880-12921/com.sanruza.alpak.tinderlike V/FA: Collection enabled
答案 0 :(得分:1)
您是否实施了sharedpreference
?
如果您为sharedpreference
实施此功能,可能需要user session
。
如果你没有实施
然后尝试从RegistrationActivity
复制代码,然后创建新的Activity
并粘贴到那里。
答案 1 :(得分:1)
是的,由于这个原因它直接进入主动:
mAuth = FirebaseAuth.getInstance();
fireBaseStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
Intent intent = new Intent(RegistrationActivity.this, MainActivity.class);
startActivity(intent);
finish();
return;}};
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(fireBaseStateListener);
}
onStart
这已经完成:mAuth.addAuthStateListener(fireBaseStateListener);
所以它进入了Listener,因为你的代码中有这个:
Intent intent = new Intent(RegistrationActivity.this, MainActivity.class);
startActivty(intent);
它将直接进入MainActivity.class
这样做:
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user!=null){ //if user is signed in
Intent intent = new Intent(RegistrationActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
else{
Log.i("sign in", not signed in);
}};