Method for Android to receive push message and jump to specified page
Raising questions
This access is a push. The push of other companies has not been studied. The idea should be similar
The app is on the front desk. At this time, a dialog box needs to pop up to remind the user whether to view the new message. If you want to view it, jump to the specified page
If the app is in the background or the app process has been recycled by the system, the app process will be pushed and pulled up after receiving the push. At this time, to display the notice, click the notice bar to open the app and jump to the target page. After closing the target page, you need to return to the application home page instead of directly launching the app
Realization idea
When the app is in the foreground, a dialog will pop up to remind the user of new messages, but the latest version of a push document inherits intentservice and cannot obtain the context required by the pop-up dialog (note that getapplicationcontext() cannot be used), so it is implemented with a dialog style activity
When the app is in the background, if the intent of the target activity is directly transmitted in pendingintent, it will directly exit the application when exiting the target activity, which feels like a flash back; If you jump to the home page, and then check whether the home page is jumped by clicking the notification to enter the application, then the home page will flash. To sum up, the methods are not ideal. A better solution is to pass an intent array to pendingintent, and place the target activity and the home page respectively. This has a better effect
When the app is in the foreground, a dialog style activity will pop up
Set activity style
AndroidManifest.xml
It should be noted that the activity here inherits appcompatactivity. If it inherits activity, some attribute settings need to be fine tuned. For example, remove the title and change it to
After the above settings, you need to set the size of the pop-up frame
The app is in the background or has been destroyed
We will pop up notifications when we receive push messages. Here, we only need to fine tune the common pop-up notification methods
The above key changes are in pendingintent, where the intents parameter stores the home page activity and target activity, such as
After the above settings are passed, click the notification bar to open the targetActivity. After returning from the targetActivity, the mainactivity will be opened instead of exiting directly
Note that the startup mode of mainactivity needs to be set to singleinstance androidmanifest.xml
The above is some content of the jump after receiving the push message. I hope it will be helpful to your learning, and I hope you can support more programming tips.