after working with my self-written db-access layer i just started
using the ContentProvider as suggested by android.
I implemented all db-access functions which i had in a class that
inherits from DatabaseContentProvider and added some of my own public
methods. These help me to initialize my database by reading stuff from
a xml file. I need to call this method explicitly after the xml file
is read. The Problem is, that i can't get my
SelfWrittenContentProvider out of the Context.
i tried with:
Using java Syntax Highlighting
- SelfWrittenContentProvider p =
- (SelfWrittenContentProvider)getContentResolver().getProvider(URI) ;
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
but this just returns an interface and if i try to cast it i get a
ClassCastException! I tried to instantiate it with
Using java Syntax Highlighting
- new SelfWrittenContentProvider();
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
but it does not work either, because the DatabaseHelper (as in the
NotepadExample) gives me a null-Database. i don't see why i need 2
instances anyway. the ContentProvider gets instantiated just as the
application starts, right? How can i reach it, for example in an
Activity or from a Context object?
or did i misunderstand the whole use of those ContentProviders? What
is the proper way to access a database? Please help me. i refactored
my whole code that i can use those ContentProviders and now i don't
know how to explicitly get my own instance in my code....
Thanks a lot
simon

