Currently, I am working on my first application using a database. Now I am a bit confused. The application is a native Android app. I'm using SQLite as DB system.
I have some trouble to work with the data. At the moment I have a class Person with a few attributes (firstname, lastname, ...). But it also contains a ID. My DatabaseHandler has a method called addPerson(Person p1). In the method, the person will be written to the DB.
The workflow I am using: My application consists of 2 pages. The first page displays a list of all persons. The second page is to create persons with a few input fields:
After clicking the create-Button I create a new object of the type Person. If the person was successfully created I call the method addPerson(Person p1). After the person is added to the DB I get the ID of the Person - from the DB - and add it to the Person object. If everything worked correctly the page will be closed and I come to the start page with the list of all created Person's.
When changing the the first page, firstly I clear the ArrayList<Person> persons and read all Person's from the DB and add it to the ArrayList: persons = DBHandler.getAllPersons();. After getting all Person's I notify the adapater that the data has been changed.
This process feels very stupid. Is that the correct way I have to go? Or should I stop working with the class Person and work only with the DBHandler? I was searching on google but didn't find anything useful what helps me out.
I have some trouble to work with the data. At the moment I have a class Person with a few attributes (firstname, lastname, ...). But it also contains a ID. My DatabaseHandler has a method called addPerson(Person p1). In the method, the person will be written to the DB.
The workflow I am using: My application consists of 2 pages. The first page displays a list of all persons. The second page is to create persons with a few input fields:
After clicking the create-Button I create a new object of the type Person. If the person was successfully created I call the method addPerson(Person p1). After the person is added to the DB I get the ID of the Person - from the DB - and add it to the Person object. If everything worked correctly the page will be closed and I come to the start page with the list of all created Person's.
When changing the the first page, firstly I clear the ArrayList<Person> persons and read all Person's from the DB and add it to the ArrayList: persons = DBHandler.getAllPersons();. After getting all Person's I notify the adapater that the data has been changed.
This process feels very stupid. Is that the correct way I have to go? Or should I stop working with the class Person and work only with the DBHandler? I was searching on google but didn't find anything useful what helps me out.