mardi 3 mars 2015

Implementing ContentProvider and ContentObserver in SQLite Database

This is my problem, and I'm looking to solve it by implementing ContentProvider and ContentObserver. My issue now is I don't know where to put what and what to put where.


I got a bit confused with most of the documentations I went through regarding the two so I'm turning to stackoverflow for some clarifications:


1) Do I have to re-encapsulate my DatabaseHelper to implement ContentProvider from



public class DatabaseHelper extends SQLiteOpenHelper {
...
}


to



public class AccDB extends ContentProvider
public class DatabaseHelper extends SQLiteOpenHelper {
...
}
}


or can I just create a separate class altogether for it.


2) Where do I place my ContentObserver, in my AccountsManager, my DatabaseHelper or do I create a new .class altogether. Does it even matter? Does defining and registering Uri's make the placement of ContentObserver irrelevant?


3) From what I read ContentProvider stores and retrieves the data while ContentObserver detects changes in data and executes something when it detects one. So in my case ContentObserver, when it detects a change, will grab data from ContentProvider and throw it to my AccountManager and tell it to refresh using the data it threw correct?


4) I saw examples of ContentObserver with and without a Handler. Which is more ideal and why ?


Lastly, as much as explanations go if someone can actually show me how to properly do it in regards to this while explaining what's going on or recommend a better method than using ContentObserver/Provider for my problem that would be perfect.


Aucun commentaire:

Enregistrer un commentaire