1
votes

I'm implementing Firebase email/password authentication into my new android app.

The app works fine for the most part, except that when the user clicks on one of the two the buttons login or registration, the app skips the supposed activity, login or registration, and goes straight into mainActivity.

This is how I have wrote the intent to open next activity:-

mRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ChooseLogin.this, RegistrationActivity.class);
                startActivity(intent);
                finish();
                return;}});

There are two errors I found in debugging which might be relevant:-

W/zygote64: Skipping duplicate class check due to unrecognized classloader W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.

As well as:-

W/DynamiteModule: Local module descriptor class for com.google.android.gms.crash not found.

Based on answers to similar issues as mine I have :

  • checked with the firebase assistant it says I'm connected.

    Firebase Assistant

  • checked that in the firebase console I have enabled email/Password login

  • checked on my device and an emulator and on both it acted the same

  • checked that I use the latest 'com.google.firebase:firebase-auth:11.6.0'

  • checked that the google play services are fine 'classpath 'com.google.gms:google-services:3.1.0'

  • even added into manifest request for internet permission

  • implemented firebases crashylytics and it doesn't catch this

  • re-added the google.services.json file and then build/rebuild the project

EDIT ( Upon request the registrationActivity and logcat ) :

registrationActivity's 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
2
remove the return - Peter Haddad
is your app crashing? and maybe show the full logcat to see the problem there - Peter Haddad
Can you please post you RegistrationActivity's onCreate code here - Rahul
@FarisKapo change your layout seems like you call login layout instead of registration layout - Tara
@FarisKapo did you check your layouts name? - Tara

2 Answers

2
votes

yes its going directly to mainactivity because of this:

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 this is done: mAuth.addAuthStateListener(fireBaseStateListener);

So it is entering the Listener and since you have this in your code:

Intent intent = new Intent(RegistrationActivity.this, MainActivity.class);
startActivty(intent);

it is going directly to MainActivity.class

do this:

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);
            }};
1
votes

Did you implement sharedpreference? Perhaps due to sharedpreference if you implement this for user session. if you didn't implement then try copy your code from RegistrationActivity then create new Activity and paste into there.