In my application I want the user to auto log out after 10 PM and can login after 10 AM only .Now I am picking the current time but I don't know how to this for my scenario ,If the application is not in background then also it should work(I should work in background) .
Asked
Active
Viewed 421 times
0
-
You can use AlarmManager to schedule this sort of stuff https://stackoverflow.com/questions/4459058/alarm-manager-example – MSpeed Jul 05 '17 at 10:43
-
when the user open's your application inside onCreate check the current time if it's between 10 PM to 10 AM close the application and show a Toast message. No need to use any kind of scheduler – sumit Jul 05 '17 at 10:44
-
Refer this answer https://stackoverflow.com/a/43062070/3946958 .. It will help u.. – Ravindra Kushwaha Jul 05 '17 at 10:44
-
1@billynomates thank you ,It helped !! – Sidhartha Jul 06 '17 at 12:52
3 Answers
1
Download the Sample by google itself, which gives all 3 types of repeating tasks example.
https://developer.android.com/training/scheduling/alarms.html

Niraj Sanghani
- 1,493
- 15
- 23
1
You can use AlarmManager to schedule repeating actions. Something like this:
myAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi); // Millisec * Second * Minute

MSpeed
- 8,153
- 7
- 49
- 61
-
I have attempted the code ...Please go through the link https://stackoverflow.com/questions/44963723/alarmmanager-not-invoking-the-task/44963756#44963756 – Sidhartha Jul 07 '17 at 09:24
0
As someone mentioned in comments
Check the time when user open the app, and if he should be logged out perform the logout and perform to the LogIn activity you probably implemented.
If I misunderstood something, let me know.
If you started coding this behaviour, you can provide some code snippets

Ionut J. Bejan
- 734
- 11
- 28
-
I want to maintain one flag value as per the timing ,as per flag value I have some other work also ,So I want the time checker kind of thing in background mode . – Sidhartha Jul 05 '17 at 10:56
-
So, like when the application is off? Or like an AsyncTask that execute in background ? Check [this](https://developer.android.com/reference/android/os/AsyncTask.html) to see what I mean – Ionut J. Bejan Jul 05 '17 at 11:00