‫I'm going to use the anonymous authentication that allows users to use your app or access certain features
‫without requiring them to sign up or log in with a traditional username and password.
‫Instead, it provides them with a temporary anonymous account that Firebase manages, and you can get
‫a list of users if you select the users tab.
‫Back to our project.
‫I'll create a new package and I'll name it as repository.
‫And inside this repository I'll create a new Java class and I'll name it as repository in authentication.
‫Since I'm not going to use a traditional username and password, sign up or log in methods, I don't
‫need to use modal classes, so for that I'll directly use the repository.
‫The repository acts as a bridge between the ViewModel and the data sources, such as databases, network
‫services, and local storage.
‫The repository is responsible for abstracting the data sources and providing a clean and consistent
‫API for the ViewModel.
‫To access and manage the data, I'll create a new method called Firebase Anonymous Authentication.
‫And this method took into the parameter a context object.
‫I'll use this context object in the intents.
‫Alt plus enter to import this context, and inside this method I'll start with Firebase auth dot get
‫instance dot sign.
‫In this line of code is used to initiate anonymous authentication in an Android application using Firebase
‫authentication.
‫Firebase auth dot get instance.
‫This part initializes the Firebase authentication system for your Android app.
‫It gets an instance of the Firebase auth class, which is the entry point of all Firebase authentication
‫operations in your app.
‫Sign in anonymously.
‫This is a method provided by Firebase Authentication.
‫When called, it attempts to sign in the user.
‫Anonymous authenticate session generates a temporary and unauthenticated account for the user.
‫This can be useful for allowing users to access some basic features of your app, without requiring
‫them to create a full account.
‫It's typically used in scenarios where you want to personalize the user experience, but don't need
‫the user to provide any personal information.
‫Also, I intended to use this type of authentication because we learned before how to use password and
‫email authentication in the journal app.
‫And in this app, I'm going to use a different way, which is anonymous authentication.
‫If you want, you can use any other authentication system.
‫After calling sign in anonymously method, you can handle the result in a callback or using asynchronous
‫methods to check if the sign in was successful and if needed, link the anonymous account to a permanent
‫account or perform other actions.
‫I'll start with add Oncomplete.
‫Listener pass and you Oncomplete listener in order to override the Oncomplete method.
‫So this method will be called when the authentication is successful.
‫Let's start.
‫This is the task.
‫If task is successful, we need to direct the user to another activity.
‫So intent I equals to new intent.
‫And here I need to use the context object that I passed as a parameter.
‫And I'll create a new activity called groups activity.
‫I dot add flags, intent dot flag, new task and context dot start activity I this line of code and
‫the flag in activity.
‫New task indicates that a new task should be created for the activity that is being started.
‫This means that the new activity will be started in a new task, rather than within the same task.
‫Backstack as the calling activity.
‫And this line of code prevents many errors.
‫You should use it when calling intents and when moving from one activity to another outside the activity.
‫So this repository is outside the main activity.
‫I'm not moving from this main activity to the groups activity.
‫I'm moving from the main activity to the groups activity in the repository.
‫So I need to use this line of code, and I use the context object to start the activity and launches
‫the new activity and a new task.
‫I'll create this new activity.
‫So inside a new package I'll name it as views.
‫I'll create a new activity, new empty views activity.
‫And I'll name it as Groups Activity Java and click finish.
‫Close it for later on and import this group's activity class.