0

I'm making an android app which displays the list of male and female from database with a user specified age. I almost managed to write the code the below is my code as far as I made

public class UserList{
private ArrayList<String> maleList;
private ArrayList<String> femaleList;}  //getter setter for Arraylists 


 // method to get data
 public UserList getUserLists (Context context, String age){
public UserList userList = new UserList();
public ArrayList<String> maleList = new ArrayList<String>();
public ArrayList<String> femaleList = new ArrayList<String>();
db = dbhelper.getWritableDatabase();
Cursor cursor = db.rawQuery(
            "select * from USER_INFO where AGE = ?", new String[]{age});
if(cursor != null)
{
    if(cursor.moveToFirst())
    {
        do{
              String user_id = cursor.getString(cursor.getColumnIndex("USER_NAME"));
              String gender = cursor.getString(cursor.getColumnIndex("GENDER"));
              if(gender.equalsIgnorease("MALE"))
                  maleList.add(user_id);
              else
                  femaleList.add(user_id);
          }while(cursor.moveToNext());
          cursor.close();
    }
}
userList.setMaleList(maleList);
userList.setFemaleList(femaleList);
return userList;
 }

But now I need to call this function for getting data from database to cursor in certain intervals like after every 5 minutes. Please help me in doing that the age variale used is age.

madhan kumar
  • 1,560
  • 2
  • 26
  • 36
user3781907
  • 109
  • 1
  • 4
  • 13

1 Answers1

1

You should implement a broadcast receiver and setup an alarm scheduled at regular interval. There is a simple tutorial on how to do that here : alarm-manager-example

Community
  • 1
  • 1
gtosto
  • 1,381
  • 1
  • 14
  • 18