Context of the page and SQLite database

Is it possible for the data in my SQLite database to have values other than my View when changed in the MyApplicationName.Droid project?

I do not know if it's exactly the source of the problem but I'll explain how my application is working. I have a View in my PCL project with a ListView that is loaded the first time I start the application, after this load I make a call to a class in the MyApplicationName.Droid project via DependencyService and there starts a routine where the values of the objects of my ListView are changed and updated, the problem is that when I click on any item in my ListView to load the data, they do not have the values that were updated, this only happens when I close my page and open it again.

What could be happening? Thank you.

I would like to share here the project code to find the error and make it clear what is happening, however, my application has a lot of code in this routine.

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I have a View in my PCL project

    Stop. You know that PCL is long since deprecated, right? .NET standard is the expected type for a shared project.

    I make a call to a class in the MyApplicationName.Droid project via DependencyService and there starts a routine where the values of the objects of my ListView are changed and updated

    That seems really odd... Unless the values are coming from hardware like serial numbers or something like that. Otherwise it seems odd that your objects are being changed from a DependencyService.

    they do not have the values that were updated, this only happens when I close my page and open it again

    Your MVVM databinding is messed up. Either the objects aren't observalbe... aren't throwing INotifyPropertyChanged or the collection that is the source for the ListVIew isn't an ObservalbeCollection... Or something to that effect... Like that weird way you're updating your objects probably isn't raising any update/change events. So the UI is never told that there has been a change that it needs to pull.

    my application has a lot of code in this routine.

    Sounds like another problem. Small discrete functions that have a single purpose in life are far more manageable that massive sequential methods. As soon as you have to make this apology/excuse to others you know you have a problem that should be refactored.

  • renanbarbosarenanbarbosa Member ✭✭
    edited April 3

    Your MVVM databinding is messed up. Either the objects aren't observalbe... aren't throwing INotifyPropertyChanged or the collection that is the source for the ListVIew isn't an ObservalbeCollection... Or something to that effect... Like that weird way you're updating your objects probably isn't raising any update/change events. So the UI is never told that there has been a change that it needs to pull.

    The ListView is correctly associated with an ObservableCollection and the MVVM connection is also correct.
    The strange thing is that a property of my object is updated in the ListView because of the ObservableCollection but the moment I load the ListView object queried the database, the object comes with the old values. When I navigate to another page and then return to the page with ListView creating a new instance of that page, I can load the updated data.

    Sounds like another problem. Small discrete functions that have a single purpose in life are far more manageable that massive sequential methods. As soon as you have to make this apology/excuse to others you know you have a problem that should be refactored.

    The codes are structured in small methods, or flow into the architecture of the application that makes or extends the project, thank you very much for the observation.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    the object comes with the old values.

    Sounds like you have multiple instances and aren't binding to the same one all the time.

    When I navigate to another page and then return to the page with ListView creating a new instance of that page, I can load the updated data.

    That's always a hint that the changed event/notification isn't being heard. So something somewhere along the chain of binding is off... the model isn't sending updates... the binding is oneway... the property is a CLR property instead of a BindableProperty... Some piece in the chain is not broadcasing the change.

  • renanbarbosarenanbarbosa Member ✭✭

    I've been scouring the whole code and the problem does not seem to be related to the ListView, every time I load the object in the MyApplication.Droid project I update the properties and they are updated using OnPropertyChanged(), after that I close the connection with the data base and destroy the object to prevent it from being associated with multiple instances. In another part of my application, in the Portable project, i try to access this object based on the ID to get the updated values and even then to no avail.

  • Liêm_NguyễnLiêm_Nguyễn USMember ✭✭✭✭

    Show your code!

Sign In or Register to comment.