How to get a ContentProvider (from Context)

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

How to get a ContentProvider (from Context)

Postby bAZtARd » Fri May 30, 2008 3:02 pm

Hi all
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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. SelfWrittenContentProvider p =
  3. (SelfWrittenContentProvider)getContentResolver().getProvider(URI) ;
Parsed in 0.013 seconds, using GeSHi

but this just returns an interface and if i try to cast it i get a
ClassCastException! I tried to instantiate it with

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. new SelfWrittenContentProvider();
Parsed in 0.010 seconds, using GeSHi

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
Posts: 8
Joined: Wed Apr 09, 2008 11:03 am


Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 5 guests