As soon as the software for Android os cam starts, it must verify that an individual are closed in

As soon as the software for Android os cam starts, it must verify that an individual are closed in

Step 1: Handle User Sign-In

If that’s the case, the software should go ahead and highlight the items in the speak room. If not, it must reroute the consumer to either a sign-in monitor or a sign-up monitor. With FirebaseUI, promoting those screens requires much less code than you possibly might envision.

In the onCreate() approach to MainActivity , verify that an individual is signed in. To get this done, find out if the existing FirebaseUser item just isn’t null . Whether or not it’s null , you have to develop and configure an Intent object that opens a sign-in activity. To accomplish this, utilize the SignInIntentBuilder class. When the purpose is ready, it is vital that you release the sign-in activity by using the startActivityForResult() technique.

Keep in mind that the sign-in task additionally permits new registered users to register. Thus, you don’t have to create any additional laws to carry out individual registration.

As you can tell inside preceding rule, if the consumer is signed in, we initial showcase a Toast pleasant an individual, then call an approach called displayChatMessages. For the present time, only establish a stub for it. We’re going to feel including laws to they after.

After the user provides signed in, MainActivity will get an end result as an intention . To take care of they, you need to override the onActivityResult() method.

In the event that lead’s rule is actually RESULT_OK , this means the consumer features closed in successfully. If so, you have to name the displayChatMessages() way again. Usually, call finish() to close the software.

Step Two: Deal With User Sign-Out

By default, FirebaseUI utilizes brilliant Lock for Passwords. Consequently, the moment the consumers sign in, they will remain signed in even when the software was restarted. To allow the people to sign on, we’re going to now create a sign-out substitute for the overflow selection of MainActivity .

Build another diet plan source file labeled as main_menu.xml and include a single items to it, whose concept feature is scheduled to indication . The belongings in the file should look along these lines:

To instantiate the diet plan resource inside MainActivity , override the onCreateOptionsMenu() strategy. Subsequently call the inflate() method of the MenuInflater item.

Next, override the onOptionsItemSelected() approach to deal with click activities regarding the diet plan product. Within the technique, you can easily contact the signOut() technique of the AuthUI course to signal the consumer away. Since sign-out procedure is performed asynchronously, we’re going to include an OnCompleteListener to they.

Once the individual has finalized aside, the software should shut automatically. This is why the reason why you read a call with the finish() way from inside the laws above.

5. Produce A Product

To be able to store the chat information during the Firebase real time database, it is vital that you create a design for them. The layout regarding the chat message, which we produced earlier on contained in this guide, have three opinions. To populate those horizon, the design also must-have at the very least three areas.

Make a brand new Java lessons labeled as and incorporate three associate variables to it: messageText , messageUser , and messageTime . In addition, create a constructor to initialize those variables.

To make the design suitable for FirebaseUI, you need to include a default constructor to they, in conjunction with getters and setters for the member factors.

6. Post A Speak Content

In the listener, you should very first see a DatabaseReference item utilising the getReference() approach to the FirebaseDatabase class. You may then phone the push() and setValue() strategies to put brand-new instances of the ChatMessage course on real-time databases.

The ChatMessage cases must, naturally, end up being initialized with the contents of the EditText and also the screen term for the currently signed-in user.