Android Question Use service module to execute database routines

Anser

Well-Known Member
Licensed User
Longtime User
Hi all,

I am looking for a basic sample that uses 2 activities and a service module. The activities will request the service module to:-

  1. return the results of queries
  2. do the inserts new records to the database
  3. updates the records in the database etc etc.

I don't want each activity to have individual database connection objects, because when switching from one activity to another I will have to close the connection with the database, then on the new activity I will have to create a new connection object and then connect to the database. All these will slow down the apps performance.

What I am looking for is that when my app starts the service module should also start and will connect to the database and will be ready to serve the requests from other activity modules of my app. When my app quits, the service would close the connection to the databse and the service should also be destroyed. So the connection to the database is established only once (I may have to handle connection timeout too), the database connection is closed once I quit the app.

I don't know whether the above said is the right approach or not OR whether this can be achieved using B4A.

I understand that, from the activities I should use Result = CallSubDelayed2(ServiceModuleName, SubNameToBeCalled,ParameterToBePassed). It will return the data as a list/list of Maps etc

I searched the forum but could not locate anything similar to what I need when it comes to a service module and database.

A basic skeleton of a service module would be fine. A push in the right direction will be appreciated. This will be useful for newbies like me.

Regards
Anser
 

edgar_ortiz

Active Member
Licensed User
Longtime User
You can not "run" MySql on android device.

If your database is in a server you must use "Web Service" to access the data.

Regards,

Edgar
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Edgar,

My B4A app will be connecting to a remote MySQL database available on the Internet cloud.

I am aware about the different solutions available here to connect to a remote MySQL for eg php, RDC, MySQL lib etc.

Regards
Anser
 
Upvote 0

edgar_ortiz

Active Member
Licensed User
Longtime User
Hi,

You can check:

https://www.b4x.com/android/forum/threads/connect-android-to-mysql-database-tutorial.8339/

https://www.b4x.com/android/forum/t...connector-rdc-connect-to-any-remote-db.31540/

https://www.b4x.com/android/forum/threads/connect-android-to-mysql-database-tutorial.8339/#content

I have few apps that use My-Sql in the server and Sqlite in the phone and I'm using a web service in PHP that only send the information to the database and then process the response.

And everything runs fine.

Regards,

Edgar
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Edgar,

Really appreciate your effort to help me.:)

I am looking for a sample or some inputs/advices from the fellow members here on how to use the database via a service module in the app.

I was able to locate a file downloading service sample. May be I can use that as a base to start off with my Service module coding.

Regards
Anser
 
Upvote 0
Top