You can use the URI parameter:
List<String> android.net.Uri.getPathSegments()
If your URI, for example:
content:
MyTable will be in the list returned by getPathSegments(); .
Then you need to specify your table in the URI and in the insert, update, query, delete methods in the provider, construct the query depending on the URI parameter.
To avoid testing in a URI, you can add an Annotation method called getTableName() to your provider, which will return your tableName as a String .
Then extend your provider to the 5 classes Table1Provider , Table2Provider , etc. and implement the method
Class abstract MyProvider extends ContentProvider{ public abstract String getTableName(); @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Then create an instance of Table1Provider instead of the abstract provider.
source share