I need to run a complex custom animation in an Android app. For this, I wrote a function that needs to be called repeatedly and uses the current time-stamp to calculate positions, colors, shadows, etc. of View elements on the screen.
There seem to be a whole bunch of different approaches I could use to have this function called:
- Standard Java Multi-Threading with Activity.runOnUIThread
- "Tail-recursive" View.post calls
- Timers
- AsyncTasks
- God knows what else... :)
In my current implementation I'm just calling my animation-function from a separate thread via runOnUIThread. While it works, it doesn't seem like a good idea as it might flood the event queue with messages faster than they can be handled or are needed given the screen refresh...
I posted a similar question for iOS a couple hours back and @IanMacDonald had an amazing answer for me that allows my function to be called once before every screen refresh and it makes for awesomely smooth animations. Is there something similar that I can do in Android, i.e. have it call my function every time the screen is about to be refreshed?
If possible, I would like to use a method that is as backward-compatible as possible, preferably API 7 or below...