Android Question Notification persists

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello team,

I have created my first chat websocket server using this example. After that i am trying this example for android client.

At PushService there is sticky service declaration that is obsolete, so i change it:
B4X:
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
which cause a notification that always persissts. If I don't set it and kill it from recent apps then no notification will come and all messages are lost.

So the problem is that all mainstream chat apps does not have a persistent notification in order to show notifications, so what is the problem?

I searched on forum and tried to implement solution from background gps example with same luck. Persistent notification or lost messages-notifications.

Moreover, if i kill it from recent apps and send many messages from other device to that one, server throws this error:
B4X:
java.lang.RuntimeException: java.lang.RuntimeException: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:523)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:494)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:568)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:180)
    at b4j.example.main._appstart(main.java:124)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.main(main.java:28)
Caused by: java.lang.RuntimeException: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:514)
    ... 13 more
Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:690)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
    at anywheresoftware.b4j.object.ConnectionPool.GetConnection(ConnectionPool.java:62)
    at b4j.example.pushshared._updatebrowsers(pushshared.java:832)
    at b4j.example.pushshared._newconnection(pushshared.java:151)
    at jdk.internal.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    ... 14 more
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@702b8b12 -- timeout at awaitAvailable()
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1467)
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
    ... 22 more

main.main (java line: 28)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.example.main.main(main.java:28)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:523)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:494)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:568)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:180)
    at b4j.example.main._appstart(main.java:124)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    ... 2 more
Caused by: java.lang.RuntimeException: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:514)
    ... 13 more
Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:690)
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
    at anywheresoftware.b4j.object.ConnectionPool.GetConnection(ConnectionPool.java:62)
    at b4j.example.pushshared._updatebrowsers(pushshared.java:832)
    at b4j.example.pushshared._newconnection(pushshared.java:151)
    at jdk.internal.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    ... 14 more
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@702b8b12 -- timeout at awaitAvailable()
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1467)
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
    ... 22 more

I attach you B4A client project and three modules from jrdc2 websocket server. This websocket server files are using an online SQL instead of SQLite.


Thank you for your time.

p.s. Pixel 5 with Android 12
 
Last edited:

yiankos1

Well-Known Member
Licensed User
Longtime User
You should use Firebase to implement push notifications. They will work without you needing to keep a running service.
Thank you Erel for your answer. As i read at your tutorial, this notification can't open any page. So, my whole project should be rebuild as a normal Android project, bacause of notifications does not work properly either way?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
So, my whole project should be rebuild as a normal Android project
That's a mistake, you shouldn't do that nowadays.

bacause of notifications does not work properly either way?
Why would the notifications not work?
I think you mean this:
"Don't try to access B4XPages from FirebaseMessaging service. B4XPages can only be created after the main activity was created."
If you click on a notification, then the app is opened and accordingly also the Main Activity, from there you can go to the B4XPage

Just try it out and if you have any questions, the forum is there.
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Thank you Alexander!
I tried this example, but clicking the notification does not fire main activity. Does not do anything... Should i add something at Activity_Create(FirstTime As Boolean) or Activity_Resume sub?

You can watch this video demostrates what i am saying
 
Last edited:
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
I can only tell you very roughly what to do, I looked into my social network, which I had developed in 2020, I already had B4XPage in use.

In the FirebaseMessaging Service:
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)

'in here you build the notification with NB6

End Sub
Use the NB6 lib. for that

In NB6 if you are build the notification with:
nb.Build... One parameter is the activity that should be started when you click on the notification. There you use the "Main"

If you then click on the notification, check if it is a notification with the following code in the main module:
B4X:
Sub Activity_Resume

If Activity.GetStartingIntent.HasExtra("Notification_Tag") And Intent1 <> Activity.GetStartingIntent Then

'You notification with your extra

End If

End Sub

I hope you can do something with it.
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Do you send the notification using the Firebase console or B4J app?
From Firebase/Project Settings/Cloud Messaging, Cloud Messaging API (Legacy) was disabled and only Firebase Cloud Messaging API (V1) was enabled. So i enabled cloud messaging in order to get server key and put it in non-ui b4j project to send a notification. Notification WORKED! Thank you @asales and @Alexander Stolte
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…