Ok, I want to create a counter to show after user click something
think like iMobster, where after you click something you’ll have a 5 mins timer and after that it’ll increase your HP by 1…
To be honest I don’t know how to code it using AlarmManager or anything else better, plus If let’s say the alarm is running and the user lost another HP that means you’ll have to add another AM for another 5 mins…
Maybe someone got better logic for it?
You don’t want to use AlarmManager for this. AlarmManager should be used for cases where you know in advance the specific time/date you want your code to execute; instead, you want to execute some code N minutes from now, which you’d do with a Handler and postDelayed.
And then define your Runnable as an instance in your class:
If you wanted to only run once, you’d omit the postDelayed() call from the code inside your Runnable. So maybe you’d call a postDelayed() on your Handler each time an action is taken that you want to add or subtract hitpoints for, and after the specified amount of time has passed it’d execute and be done.