Currently my app starts with Splash Activity and checks if user is on Firebase Authentication. And if the user's on the authentication i take him to MainActivity.class. If the user's not, i take him to Login Activity.class then after the signup, it takes me to MainActivity.class.
When I first start the app, of course the app will take me to Login Activity. And i authenticate myself and go to MainActivity screen. The problem is when i press back button, it takes me to Login Activity.class screen. I want to just exit the app. How can I fix the problem? This is my code for SplashActivity.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class SplashActivity extends Activity {
private FirebaseAuth mAuth = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
if (user!= null){
startActivity(new Intent(SplashActivity.this, MainActivity.class));
}
else{
startActivity(new Intent(SplashActivity.this, LoginActivity.class));
}
finish();
}
}