2
\$\begingroup\$

Hello I'm looking for a bit of advice in which way is the best to proceed creating my applications 'gameloop' - It doesn't want to be a game loop in the truest sense since I'm not really rendering any graphics just displaying some animated gifs.

My goal is to have a task that runs every 30 minutes that decrements pet variables

Example Method 
passTime { <pets health> = <pets health> - 1; <pets hunger> = <pets hunger> -1; <pets exp> = <pets exp> + 5; } et

c. I was wondering the best way to go about this? AsyncTask will be of no use since this ideally wants to be running even when the app isn't.

I would rather use an IntentService subclass rather than a Service subclass but I can't seem to get the IntentService to run through a pendingIntent via the AlarmManager.

So I'm asking advice on the best way to proceed from the ground up with this. Thank you!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Could you just record the time of the last 'feed time' or 'pass time' and on app-open check then? Or is this not okay, since the pet cannot have damage done when the phone is off? \$\endgroup\$ Feb 23, 2013 at 0:39
  • \$\begingroup\$ I could do this but for example if I had it running through a service I could notify the user when certain conditions are met if (pet.hunger <10) { toast,notification etc..} the idea is for the app to have its own 'digital' timeline (or loop) (starting from when user selects pet) \$\endgroup\$ Feb 23, 2013 at 0:50

1 Answer 1

1
\$\begingroup\$

If you are looking for your 'tick' method to be called every X minutes, you could look at using a timerTask. This will allow for your method to be called at a specific time.

You can find some more information and an example here: http://enos.itcollege.ee/~jpoial/docs/tutorial/essential/threads/timer.html

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .