I am trying to make an android application that will identify how much time is left for a task to be completed. I have followed Vogella's tutorial, particularly this part http://www.vogella.com/articles/AndroidSQLite/article.html#todo to make a contentprovider and database. It populates a listview with two things, the name of the task and how many days are left (the latter is calculated when the user selects his end date in another activity). My app calcualtes the current date and subtracts it from the end date and stores how many days are left in the database. The problem is that this is only stored once. Three days from now it will still say 4 days left. I want the app to check for how many days are left every time the client starts it (check current date, subtract from end date and update that column in the database). The problem is I'm not sure how to do it. If somebody could give me some guidance I would appreciate it.
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.
ContentResolver is used to select the right ContentProvider based on the ContentUris . A ContentUri may look like. content://com.android.contacts/contacts/3. content:// is called scheme and indicates that it is a ContentUri.
You can implement as many as you want, as you can see from the documentation here. To register a content provider, you need to add its corresponding <provider> tag in the Android Manifest. In most cases, however, you won't need multiple content providers. One is usually enough, as it can handle multiple tables.
do the calculation then do getContentResolver().update(uri,values,selection,selectionArgs);
EDIT:
so just update with the values
ContentValues values = new ContentValues();
values.put(HabitTable.TIME); //whatever column you want to update, I dont know the name of it
...//any other values you want to update too
getContentResolver().update(HabitTable.CONTENT_URI,values,HabitTable.ID+"=?",new String[] {String.valueOf(id)}); //id is the id of the row you wan to update
obviously you will need to replace stuff with the correct column names
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With