All health!

Just recently (most recently) began to master the development of applications for android.

Introductory: There is an Android studio. There is one database with six tables per sqlite. There are four activites that display data from this database. The selection of data for each activation is made by a query from the database based on the data transferred from the previous activation.

My implementation: when I start each activation, I connect to the database with a new one and pull out the necessary data with a request. I push everything into an array that is bound to RecycledView. Everything works and even seems to be pretty good =)

Doubts: I am confused by the part of the database connection in each activity. It seems to me somehow abnormal. Google did not suggest a suitable answer and / or other implementation. I want to make one connection and then use it, then at the end close it. And then with each transition a new one is created, but not Feng Shui. There are concerns that this may be a bottleneck for larger projects.

Question: How to work with the base in one "session" with one connection?

ZY There are puns with terminology, please forgive. I'm new to the Android family =)

  • You have to be completely embarrassed - the distillation of data from the database into an array of disproportionately high costs than opening a connection with each call, this is only done in simplified training examples. on the connection - you can open it somewhere once in the successor of Application and then not even close it , but your version is normal - pavlofff
  • Thank you for the substantive criticism, we will study further! I did everything according to educational examples =)) - Alexander Protodyakonov
  • Read the first link. In justification, I can say that I’m not pumping the entire table (s) into the arrays, but only the data that I need and the data I need - as a result of the request, I receive from 5 to 10 elements, rarely more than 10. - Alexander Protodeaconov
  • Your solution, in addition to the cost of copying resources, has many other significant drawbacks, such as the need to process two data sources - your array and data in the database, synchronize them (changing, adding or deleting values ​​in the array should do the same in the database and vice versa - double work and extreme architecture). array - dynamic data, they exist as long as the object in which it was created exists, for example, if the device is rotated, this array will be lost or additional actions need to be taken to save it - all this is superfluous .. there are many other problems - pavlofff
  • =) Tin! I understood you. I'm going to study. Silent - Alexander Protodeacons

0