Unsolved Postgres and Threads
-
Hi,
i want to open a database connection to another thread and in this connection instance i want to subscribed into notifications. The problem is that notify not work in this case. When i open database in the main thread everything works good. But is necessary to open the database connection to another thread in order to be able to receive even when the app is in the background or when the screen of the mobile is off.Any ideas?
-
How this is specific to Mobile and Embedded? You should ask in General and Desktop topic group.
-
Because postgres driver for android has the problem with the threads.
-
@NickV How can a second thread help in case the app is in background? For that on Android (don't know about iOS) you need a background service.
-
@NickV you need allow your application run in Android background. This does not relate to multithreading but to AndroidManifest.xml setting instead.
<meta-data android:name="android.app.background_running" android:value="true"/>
-
@Gourmet your solution is not completed. I've read that i should create a service and then run the service in the background. https://doc.qt.io/qt-5.10/androidservices.html
But i don't know how to create a service in order to run it in the background. Any good tutorial will be great!
Thanks in advance! -
@Gourmet my mistake! Now it works with your solution! I'll try some tests!
-
@Gourmet i've tested your solution. Everything worked for about one hour. But again the postgres notification signal stop working after a long time. This happens only when the app is in the background for a long time.
-
@NickV check for the some apps dispatching application can kill this process for battery optimization.
-
@Gourmet thanks again. I hope to figure out what is going wrong! I believe that the problem is with the postgres driver. I believe it stops subscriptions. I will check if i am correct with this and then i will think a possible solution. Thanks again!