Iam fresher in android I selected Start date and end date from datepicker based on that I need to insert dates between start date and end date into sqllite and then compare with current date and set reminder. Please let me know if you have solution
Asked
Active
Viewed 1,499 times
1 Answers
1
To get date from Date picker use this
DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth() + 1;
int year = datePicker.getYear();
Set the values to database
public void onDateSet(DatePicker view,int year,int monthOfYear,int dayOfMonth){
dateTime.set(year,monthOfYear,dayOfMonth);
int year = year; // Here you can get day,month and year.
int month = monthOfYear;
int day = dayOfMonth;
ContentValues values = new ContentValues()
values.put("Day",dayOfMonth);
values.put("Month",monthOfYear);
values.put("Year",year);
}
You can get the database tutorials from here, here and here
To get Current date
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
To set a reminder you can use the alaram manager to set the reminder the solution can be found here
EDIT 2
private class myReminderTask extends AsyncTask<Void, Void, Void>{
ArrayList<String> list = new ArrayList<String>();
@Override
protected Void doInBackground(Void... params) {
while(true)
for(String s : list){
Date d = //Make date from the string obtained from SQL
d.toString().equals(DateFormat.getDateTimeInstance().format(new Date()));
//Create an alaram or notification
}
return null;
}
@Override
protected void onPreExecute() {
Cursor c = null;
c = db.rawQuery("select startDate,endDate from tablename" , null);
if (cursor.getCount() != 0)
{
if (cursor.moveToFirst())
{
do
{
list.add(cursor.getString(cursor.getColumnIndex("FirstDate")));
list.add(cursor.getString(cursor.getColumnIndex("LastDate")));
} while (cursor.moveToNext());
}
db.closeDatabase();
}
cursor.close();
super.onPreExecute();
}
}
Do the entire thing on AsyncTask (example here also )so that the main UI thread is not blocked, on pre execute code the database fetching and on do in background use the while loop so that it never ends
This is what i can give rest you do the work... and that's all, rest you have to search and work out your way don't expect me to make and give an entire project

Community
- 1
- 1

Girish Nair
- 5,148
- 5
- 40
- 61
-
thank you,i Completed to insert stratDate and fromDate in the table. but i am not able get the date and check with current date and show one reminder message when the app is open – Narendra Nov 08 '12 at 05:35
-
Retrieve data from database http://anujarosha.wordpress.com/2011/12/19/how-to-retrieve-data-from-a-sqlite-database-in-android/ and then store it in string and `currentDateTimeString .equals(date_retrieved_from_database)` and if its true show the reminder – Girish Nair Nov 08 '12 at 05:43
-
thank you,can you give me any code demo for fetching dates in store in string array then compare it with current date – Narendra Nov 08 '12 at 05:52
-
here are some tuts you can refere too http://stackoverflow.com/questions/7791892/how-to-retrieve-data-from-database-in-android-creating-database-on-sqlitebrowser http://www.dreamincode.net/forums/topic/226781-how-to-retrieve-data-from-database-to-listview/ http://www.youtube.com/watch?v=Awu7Rlsez_k http://droideplace.blogspot.in/2009/09/store-and-retrieve-data-in-sql-database.html – Girish Nair Nov 08 '12 at 06:05
-
exactly in app I need to set reminder which show message or notification when the current date is match with range of start date to end date. i confusing how to get dates and its range and how to compare with current date and set notification....please send complete solution – Narendra Nov 08 '12 at 08:25
-
Thank you Very much Girish Nair. – Narendra Nov 08 '12 at 11:17
-
your welcome, Accept this as solution if you solved it so that this question is closed – Girish Nair Nov 08 '12 at 11:23
-
notification is work,but for get the startdate - enddate range and compare current date. – Narendra Nov 08 '12 at 12:32
-
thanks for help but i have a problem in the given code. The date is defined like Date d="" here i put the query which defines the error that its not convert into the date.Make sure that i am using a sqlquery for finding the range from start date to end date. – Narendra Nov 08 '12 at 13:15
-
`SELECT StartDate From Dates_Table` will return something like this 28-June-12 `String start_date="28-June-12";` `formatter = new SimpleDateFormat("dd-MMM-yy");` `Date d = (Date)formatter.parse(start_date);` – Girish Nair Nov 09 '12 at 04:11
-
In apps i have to set alarm based on the start date and end date which are stored in SQLITE database.so, how to get both date and compare that dates to Current date and set alarm notification which can work like that apps is load or launch and current date is match with database stored date(means between start date to end date) it show alarm notification or play audio. Please if have any demo for this or code send me. – Narendra Nov 09 '12 at 05:21
-
Check these projects http://code.google.com/p/bells-android/source/browse/#hg http://code.google.com/p/plus-minus-alarm/source/browse/#git%2Fc2Client_ics_git – Girish Nair Nov 09 '12 at 05:25
-
thank you, if i enter start date and end date on edit text based on that can i insert all the date which is between the strar date and end date.send me query or code for that. – Narendra Nov 09 '12 at 05:54
-
`for (LocalDate date = startDate; date.isBefore(endDate); date = date.plusDays(1)) { //Do your code }` – Girish Nair Nov 09 '12 at 06:49
-
thank you girish u guide me alot and providing some of best best tutorial. – Narendra Nov 09 '12 at 11:37
-
Your welcome and happy diwali :) – Girish Nair Nov 12 '12 at 04:39