Authentication Android application using Firebase
with the login system using Google Account
- Firebase
- Authentication with
Google Account
- Authentication with
Add Firebase to your Android project go to Firebase Setup
Name Page | Preview UI |
---|---|
Home |
|
Choose an Account |
|
Account created |
|
Account already exist |
|
Sign out |
/** Firebase*/
implementation platform('com.google.firebase:firebase-bom:29.0.1')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.android.gms:play-services-auth:20.0.0'
- Add viewBinding
true
build.gralde (Module)
android {
...
buildFeatures {
viewBinding true
}
}
- Activity Kotlin Class
class MainActivity : AppCompatActivity() {
/** Add this */
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
/** Add this */
binding = ActivityMainBinding.inflate(layoutInflater)
/** Change this */
setContentView(binding.root)
/** Without findViewById */
binding.textView.text = "Bye bye findViewById"
}
}
- Activity Java Class
public class MainActivity extends AppCompatActivity {
/** Add this */
private ActivityMainBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/** Add this */
binding = ActivityMainBinding.inflate(getLayoutInflater());
/** Change this */
setContentView(binding.getRoot());
/** Without findViewById */
binding.textView.setText("Bye bye findViewById");
}
}
binding in kotlin can be used directly without initializing findViewById on widgets in layout xml