Android Question Issue with updating variable from locked screen

Ibrahim Saleh

Member
Licensed User
Longtime User
I'm having this frustrating problem with B4xPages. The issue is that I'm not able to change the value of a variable in the FirebaseMessaging service when I get a Push Notification while the phone is locked and the screen is off. I tried the phonewakestate lib to keep the phone state PartiallyLocked but still no change. What I want to do is update the UI layout when I get a push notification, but I can't do that while the Phone is locked. To solve that I have a boolean value that I have to update when I get this push notification. Now tho I was not able to change this boolean value. Anyone has a fix for me???
 
Solution
1. You can always update variables values.
2. Don't assume that the pages were created when the app receives a message. In most cases the app will be started when the message arrives and the main activity will not be started at all.
3. If you are sending important information in the push message (this is a mistake in most cases) then you should save it in a file. You can use KVS for this.

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You can always update variables values.
2. Don't assume that the pages were created when the app receives a message. In most cases the app will be started when the message arrives and the main activity will not be started at all.
3. If you are sending important information in the push message (this is a mistake in most cases) then you should save it in a file. You can use KVS for this.
 
Upvote 0
Solution

Ibrahim Saleh

Member
Licensed User
Longtime User
Thank you for answering @Erel ,
The page is created as the page I want to update is the MainPage. On point 3. you said that sending important information with push message is mistake, but the info I'm getting is important to do the next step of my app. I will try KVS and let you know how it goes. Thanks for the reply
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Do it the other way. As the phone is locked, the user can't see any changes anyway. When a FCM message arrives, store it into e.g. a file. When the user unlocks the phone, check the file and update the view.

If you need to show new data (screen is always on - makes only sense if you use e.g. a tablet as a screen) then use wakelock and update the view. I assume that this isn't what you want.
 
Upvote 0
Top