Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android content provider update certain columns

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.

like image 297
user2525981 Avatar asked Jul 03 '13 18:07

user2525981


People also ask

Are content providers still used in Android?

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 ContentResolver in Android?

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.

How many ContentProvider Can an app have?

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.


1 Answers

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

like image 192
tyczj Avatar answered Sep 18 '22 23:09

tyczj