Created
October 7, 2019 18:21
-
-
Save bariskarapinar/5ef9c2f918759ec8b030cef7f456f5fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.firebaseauthproject; | |
import android.content.Intent; | |
import android.support.annotation.NonNull; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import com.google.firebase.auth.FirebaseAuth; | |
import com.google.firebase.auth.FirebaseUser; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
//Check current user | |
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); | |
firebaseAuth.addAuthStateListener(authStateListener); | |
} | |
FirebaseAuth.AuthStateListener authStateListener = new FirebaseAuth.AuthStateListener() { | |
@Override | |
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { | |
FirebaseUser firebaseUser = firebaseAuth.getCurrentUser(); | |
if (firebaseUser == null) { | |
Intent intent = new Intent(MainActivity.this, SignUpActivity.class); | |
startActivity(intent); | |
finish(); | |
} | |
if (firebaseUser != null) { | |
Intent intent = new Intent(MainActivity.this, HomeActivity.class); | |
startActivity(intent); | |
finish(); | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment