简体   繁体   中英

What's the best way to send and retrieve (possibly large amounts) data to a PHP/MySQL backend on Android?

For a majority of my app to retrieve and send data to a MySQL database, I'm simply making requests to PHP scripts on a server. I find myself leaving AsyncTasks and HTTP connections everywhere throughout my app to connect to my server to get and send results. Is this common practice? Is there a more efficient and clean way to implement a CRUD type application using an external server with data on a MySQL database?

For my specific instance, I'm having trouble efficiently implementing a search of up to thousands of contacts that are stored in a MySQL database, find a specific person, and add them to their connections, similar to how people look up and add each other on Facebook. The simplest (far from the best) way I can think about approaching this is making an HTTP connection to a PHP script that queries a MySQL database table that retrieves ALL users that exist, send it to the client side, and allow the user to use a SearchView to filter through which users want to add. What would be a solution that is more efficient and uses less data?

I suppose if you are using asynctasks, you are sending requests manually. This may work, but I recommend using Android Volley , for all the reasons presented in that link.

As for the second question, heavy processing such as searching in a large database, should be done server-side. So, you should send a search query to the server and only send the filtered entries that are similar or equal to your search query. This way, you only send what you need and minimize data usage. And if the filtered results are still a large subset, you should send paginated results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM