Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force a content provider to reset when manually deleting database

In my app I have a ContentProvider attached to a table in a database with a CursorLoader that fills a ListView in one of my Activities. This table is filled empty by default and gets filled with user input data. I want to allow the user to completely delete all of their stored data and I'm deleting the entire database when this option is selected. The database is then recreated in it's default state when the user starts using the app again, just as it would the first time they used the app.

My issue is when I delete the database, the ContentProvider doesn't detect that the database was deleted and when I go back to my listview activity, the list is still there. I'm also making the app completely reload the ListView Activity instead of just resuming from memory and the list is still there even though the database is empty. The only way I can get the ContentProvider to reload is to kill the app in the system settings and then open it again.

Is there a way to forcefully restart the ContentProvider or to tell it that the data has been updated from outside of the ContentProvider class itself?

like image 950
wynalazca Avatar asked Apr 19 '13 21:04

wynalazca


People also ask

Which of the following methods is used to initialize a content provider?

onCreate() which is called to initialize the provider.

What is content provider how exploitable is it?

A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.

What is a content resolver?

Content Resolver resolves a URI to a specific Content provider. Content Provider provides an interface to query content. The way to query a content provider is contentResolverInstance. query(URI,.....)

What is the purpose of content provider in Android?

A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.


1 Answers

You can also simply use the delete method of the content provider without defining a selection:

context.getContentResolver().delete(YourProvider.CONTENT_URI, null, null);
like image 69
stef Avatar answered Oct 02 '22 11:10

stef