iamarkadyt
iamarkadyt

Reputation: 3120

Start countdown timer in my app which will work independently my app is opened or closed

My problem is: I need to start countdown timer in my app which will work independently my app is opened or closed ...or even if my smartphone is off.

I really wonder how does android standard clock app works. I mean how it counts time even when my phone is off? Could anybody help me with this? I will appreciate any answer!

Upvotes: 0

Views: 283

Answers (1)

Starscream1984
Starscream1984

Reputation: 3062

Internal to an android device will be a clock which runs from the battery and potentially syncs with network time when it has signal.

You can use AlarmManager and PowerManager to get your code to run at specific times, even if the phone is turned off:

Sometimes, it may be necessary for your android app to complete a task sometime in the future. In order to do this, you must schedule an activity (can also be a service) to be run using Android’s AlarmManager. This post will show: How to set up a receiver for the scheduled event How to create an activity from this receiver Using the AlarmManager and the created classes to successfully receive and process a scheduled event

From https://web.archive.org/web/20130724094711/http://justcallmebrian.com/2010/04/27/using-alarmmanager-to-schedule-activities-on-android/

See also: https://web.archive.org/web/20211114141053/https://www.techrepublic.com/blog/software-engineer/use-androids-alarmmanager-to-schedule-an-event/

Upvotes: 2

Related Questions