Search code examples
androiddatabaserestxamarin.androidsqlite.net

Rest calls & SQLite.NET in fragment or activity


I am building an Android app which uses activity and fragments and rest calls and a local database. Does anybody know where REST calls is ideal to be placed. I am more interested for fragments but would also like to know about activities as well. I also have a local SLQLite database and I have a method for getting the data. Because a database operation is long running is that similar to a REST call?

Thank you


Solution

  • You SHOULD NOT place long-running operations or any model logic on classes that can be destroyed by configuration changes (rotations, screen changes, phone states), these classes are designed to render the UI to the user.

    You should instead use: ViewModel (for shorter tasks, will only survive as long as the app does) and use a background thread.

    https://developer.android.com/topic/libraries/architecture/viewmodel?gclid=Cj0KCQjw09HzBRDrARIsAG60GP-qiuPnYKryrX2YYZI39988xMfqTx4s6fuk5xfKtvuPZ-XQ98DxpgEaAphmEALw_wcB

    Services (Recommended, can survive despite your app not being active), make sure to check out the documentation first and some examples.