Android and Mysql Database Communication

2019-09-12 01:36发布

问题:

  • Apps like Spotify and Instagram that their database, how fast users to click on buttons respond? How quickly without having to process the information stored in the database?
  • For example: the Spotify app, I quickly click on the follow button (a very rapid clicks). In this case, how information is stored in a database?
  • What is the best way to connect to the database and managing lots of connections?
  • Should I use the database interface? example: android sqlite
  • In the application Instagram, when I click on the button Like I quickly what happens? When information is stored in a database?

(i use volley library)

thanks

回答1:

Let us take an example scenario, when you hit a like button

  1. the first thing to do is to store in your local DB that a user has liked a particular artist
  2. Based on this, you should call an API off your backend which will record this event. But this has to be asynchronous and you shouldn't run this on the Main thread
  3. Before you wait for a response from the API, you can go ahead and update the Android view based on the local like counter (you can use sqllite for this)
  4. The backend will run a cronjob to get the total amount of likes and put them into another table column
  5. So when a new user comes after the cronjob, he/she will see the updated counter