I've recently encountered some issues with Android notifications, which I didn't know about before.
First paste a piece of code
The purpose is to notify users of something they have found around them, and then the user clicks on it to display a list. I quickly wrote the code and tested it. Then I released the version, but users kept saying that the list they clicked on was the same every time, which puzzled me. I thought it was not my problem, but I tried it myself. It was embarrassing. Sure enough, there was a problem, that is, the transmitted data was not updated. How to solve The problem is this sentence
There are four parameters in total. See the explanation of the source code.
There are four FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT I used FLAG_UPDATE_CURRENT to solve the problem. It is mainly used to update messages. For example, if you send a notification message with "123", and before clicking it, another notification message is sent with "345", then you click on both messages and get "345". So my problem was naturally solved. Question 2 Later, there is another requirement to add a notification message to display different applications. That is, the message above, notification 1 needs to get "123", and notification 2 needs to get "456". What should we do? This requires the use of the second flag. When using FLAG_CANCEL_CURRENT, the above steps are still used. At this time, you will find that when you click on message 1, there is no response, but the second one can be clicked. The reason lies in the second parameter. You need to define a different requestCode for each different message, and the problem can be solved. |
<<: How to get "Apple Recommended" for a good game? There is a routine
>>: 2-Minute Coding Tip: Don't Use Loops in Your Code
In 2021, more and more large companies will deplo...
[[131273]] The battle between Android and iOS dev...
: : : : : : : : : : : : : : : : : : : : : : : : : ...
Do you know how to use Tik Tok, which has huge tr...
Nowadays, mobile phones are updated too quickly. H...
15 practical compulsory courses for illustrator wi...
Q: How do I create a food delivery WeChat mini pr...
As a marketing planner, planning promotion activi...
Is it easy to be an agent of Chizhou Property Min...
Where is China's spring? Rapeseed knows best ...
Author: Liu Yanan Beijing General Hospital of Civ...
Xinhua News Agency, Beijing, May 12th. Astronomer...
When the sweet tangerines and mandarin oranges fr...
Mars Era 2021 Film and Television Editing Course ...
Qixi Festival, after the CP, the love objects - t...