D davemorris Active Member Licensed User Longtime User Oct 10, 2024 #1 I have an APP which communicates with a computer using network sockets (TCP protocol). The computer is only allowed to communicate with one device at a time, therefore when the App is closed (by the user), it sends a special sign-off message to the computer. Generally, the App works Ok on Android-10 and Android-14 devices. Except when the App is closed then only the Android-10 appears to send the sign-off message. The software to send the sign-off message is initiated within the Starter service sub Service_TaskRemoved() Code: ' This event will be raised when the user removes the app from the recent apps list. Sub Service_TaskRemoved B4XPages.MainPage.helper.DisconnectFromServer 'TODO This could be throwing and error in Android 14 (at shutdown). End Sub The App uses B4X pages, and the software which sends the sign-off message to the computer sits in a class which is declared in the Main Page. I assume the sign-off software is OK as it works on Android-10, when the App is closed, and will also work if activated manually within the App (on both Android-10 and Android-14 devices). Perhaps Android-14 has a problem with services - but I am not sure, any input would be appreciated. Kind regards Dave
I have an APP which communicates with a computer using network sockets (TCP protocol). The computer is only allowed to communicate with one device at a time, therefore when the App is closed (by the user), it sends a special sign-off message to the computer. Generally, the App works Ok on Android-10 and Android-14 devices. Except when the App is closed then only the Android-10 appears to send the sign-off message. The software to send the sign-off message is initiated within the Starter service sub Service_TaskRemoved() Code: ' This event will be raised when the user removes the app from the recent apps list. Sub Service_TaskRemoved B4XPages.MainPage.helper.DisconnectFromServer 'TODO This could be throwing and error in Android 14 (at shutdown). End Sub The App uses B4X pages, and the software which sends the sign-off message to the computer sits in a class which is declared in the Main Page. I assume the sign-off software is OK as it works on Android-10, when the App is closed, and will also work if activated manually within the App (on both Android-10 and Android-14 devices). Perhaps Android-14 has a problem with services - but I am not sure, any input would be appreciated. Kind regards Dave
Solution Erel Oct 14, 2024 You can't rely on TaskRemoved to be called before the process is killed. You should instead let the client send a ping message every X seconds and remove clients after X * 3 seconds, if they haven't sent anything.
You can't rely on TaskRemoved to be called before the process is killed. You should instead let the client send a ping message every X seconds and remove clients after X * 3 seconds, if they haven't sent anything.
Erel B4X founder Staff member Licensed User Longtime User Oct 14, 2024 #2 You can't rely on TaskRemoved to be called before the process is killed. You should instead let the client send a ping message every X seconds and remove clients after X * 3 seconds, if they haven't sent anything. Upvote 0 Solution
You can't rely on TaskRemoved to be called before the process is killed. You should instead let the client send a ping message every X seconds and remove clients after X * 3 seconds, if they haven't sent anything.
D davemorris Active Member Licensed User Longtime User Oct 14, 2024 #3 Hi Yes, I agree with Erel's response, a keep alive message would solve the situation but TaskRemoved does work on Android-10. It would appear that the TaskRemoved event cannot be used with certain versions of Android rendering the event handler useless for any important tasks. Can I ask is there any way that Android could raise and event like "App is about to close" ? I have also considered using the background event but the disadvantage is that it will close the communications link when the App is still running (but in background). Currently the ping method appears to be the only real solution which is not Android version dependent. Kind regards Dave Last edited: Oct 15, 2024 Upvote 0
Hi Yes, I agree with Erel's response, a keep alive message would solve the situation but TaskRemoved does work on Android-10. It would appear that the TaskRemoved event cannot be used with certain versions of Android rendering the event handler useless for any important tasks. Can I ask is there any way that Android could raise and event like "App is about to close" ? I have also considered using the background event but the disadvantage is that it will close the communications link when the App is still running (but in background). Currently the ping method appears to be the only real solution which is not Android version dependent. Kind regards Dave
Erel B4X founder Staff member Licensed User Longtime User Oct 15, 2024 #4 davemorris said: Can I ask is there any way that Android to raise and event like "App is about to close" ? Click to expand... No. There are many cases where the process is killed abruptly. Upvote 0
davemorris said: Can I ask is there any way that Android to raise and event like "App is about to close" ? Click to expand... No. There are many cases where the process is killed abruptly.
D davemorris Active Member Licensed User Longtime User Oct 15, 2024 #5 Thanks Erel - I have marked you 1st response as a solution. Upvote 0