Firebase Essentials - Android Edition by Smyth Neil
Author:Smyth, Neil [Smyth, Neil]
Language: eng
Format: azw3
Tags: Computers & Technology
Publisher: Payload Media, Inc.
Published: 2017-07-18T04:00:00+00:00
26.4.
Designing the User Interface
This example project will use the existing “Hello World” TextView in the activity layout to display the data associated with incoming messages. All that is required is to change the ID for the view.
Load the activity_messaging.xml file into the Android Studio layout editor, select the TextView object and change the ID in the Properties tool window to myTextView.
26.5.
Obtaining and Monitoring the Registration Token
When an app first makes use of cloud messaging, it is assigned a registration token which uniquely identifies the app and the device on which it is running. This allows messages to be sent that target a specific app running on a specific device.
The registration token takes the form of a string and may be accessed by implementing a service within the project that extends the FirebaseInstanceIdService class. This service needs to implement a method named onTokenRefresh() which is called when the app is first assigned a registration token, and then subsequently any time the token changes. Events that typically cause the token to change include the user uninstalling and then re-installing the app, the app being restored during a device recovery operation (or a move to a new device), or the user clearing the app data from the device. Given these possibilities it is important to ensure that the app is always using the current registration token.
Add a new service to the project by right clicking on the app -> java -> <package name> entry in the project tool window and selecting the New -> Java Class… menu option. In the New Class dialog, enter FirebaseIDService into the Class Name field and select the FirebaseInstanceIdService class as the superclass before clicking on the OK button:

Figure 261
Edit the newly created FirebaseIDService.java file and modify it so that it reads as follows:
.
.
import android.util.Log;
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6414)
Kotlin in Action by Dmitry Jemerov(5063)
Odoo 15 Development Essentials - Fifth Edition by Daniel Reis & Greg Mader(3351)
Odoo 15 Development Essentials by Daniel Reis(2814)
React Native - Building Mobile Apps with JavaScript by Novick Vladimir(2531)
Learning Angular - Second Edition by Christoffer Noring(2358)
Pride and Prejudice by Jane Austen(2350)
Mobile Forensics Cookbook by Igor Mikhaylov(2017)
Computers For Seniors For Dummies by Nancy C. Muir(1996)
Bulletproof Android: Practical Advice for Building Secure Apps (Developer's Library) by Godfrey Nolan(1874)
Android Development with Kotlin by Marcin Moskala & Igor Wojda(1799)
Building Android UIs with Custom Views by Raimon Ràfols Montané(1791)
1936941139 (N) by Bob Rosenthal(1732)
Building Progressive Web Apps: Bringing the Power of Native to the Browser by Ater Tal(1727)
Hands-On Internet of Things with MQTT by Tim Pulver(1706)
Android App Development by Franceschi Hervé J.;(1702)
Ember.js in Action by Joachim Haagen Skeie(1689)
Hands-On Design Patterns with React Native by Mateusz Grzesiukiewicz(1656)
