How should I call the onDraw() method of an Android view 30 times per second

For Android, I have a custom view which I fill up with primitive shapes in the onDraw() method.

Coming from a Processing background, I expected the draw method to be called automatically 30 times per second, but its clear that that's not how android views work.

So how should I go about calling this method 30 times per second?

Asked by: Owen549 | Posted: 20-01-2022

Answer 1

Use an Animation, and call startAnimation() on it from your View.

I don't know that you can set a target framerate -- rather, you're expected to set start and end points in time, and be able to interpolate for any point in time between the two.

If you don't like this approach, you might consider having another thread which periodically calls view.postInvalidate() to request that your View be redrawn.

Answered by: Kirsten139 | Posted: 21-02-2022

Similar questions

Real-time audio processing in Android

I'm trying to figure out how to write an app that can decode audio morse code on the fly. I found this document which explains how to record audio from the microphone in Android. What I'd like to know is whether it's possible to access the raw input from the microphone or whether it has to be written/read to a file. Th...

Processing more than one button click at Android Widget

I saw this topic and implement IntentService as describes, but what if I want more than one button? How can I distinguish button from each other? I'm trying to setFlags, but cannot read it at onHandleIntent() method: public static class UpdateService extends IntentSe...

Processing RSS Feeds with Namespaces in Android

I'm trying to write an XML parser that takes an RSS feed & fetches the image urls shown in the url attribute of the <media:thumbnail> tag. This is all being done via android.Util.Xml, & is an adaptation of the code shown here. An example RSS feed that I'm trying ...

signal processing - Change the playback rate of a track in real time on Android

I would like to know if somebody knows a library to changing the playback rate of a track in real time. My idea is to load a track and change its playback rate to half or double. Firstly, I tried with MusicPlayer but is was not possible at all and then I tried with SoundPool. The problem is that with SoundPool I can´t change the rate once the track is loaded. Here is the code I am using (proof of concept):

image processing - Sobel Edge Detection in Android

As part of an application that I'm developing for Android I'd like to show the user an edge-detected version of an image they have taken (something similar to the example below). To achieve this I've been looking at the Sobel operator and how to implement it in Java. How...

image processing - Picture editor in Android

I am quite new to Android development and I wish like to develop my first app which is a picture editor. Basically it can let the user adjust the brightness, contrast, black and white effects. I would like to ask which package should I look for? I have roughly go through the Android API and I couldn't found any related packages. Anyone can help me?

opengl es - 16 bit images and android processing

Am i correct in saying a 16 bit image will be decode and drawn faster than a 24 or 32 bit? I know the file size will be less but if the bitmaps will actually be drawn faster than it would be worth the effort to convert them. If it is faster, how would i go about saving a 16 bit jpeg file? I only found an option in photoshop to save a 16 bit bitmap...which is 54 MB.

I need a simple java example of processing a JSON response via HTTP for Android App?

I am writing a simple Android app and have a database that will send back information into the app. I am new to Android and am looking for a simple example that demonstrates how the Android App can process a JSON response received from a HTTP request. I need to see what classes are used for Android apps to process a HTTP response. A reference to a good tutorial, or if you're keen, write a very basic method to do th...

Android handling out of memory exception on image processing

This is the sequence part of this question: Combining 2 Images overlayed so the problem is: if the image size is too big - it'll got an exception (out of memory exception) what i want is, to handle even if the handset got the lower spec hardware, it doesn't go to that exception (but it'll take a longer time to process the image)

java - Processing for Android and regular input apps

Processing has Android support and it seems to be pretty awesome from my 10 minutes of playing with it. But I would like to make a regular (nongraphics) application like a twitter feed reader or something. So is there something like Processing that can do regular apps? Besides Titanium... Basically I am looking for anything that will make coding for android easier, processing was so easy to get working that I wa...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android