Touch handling is extremely laggy on Android

I’m developing an Android app to edit basslines.

The app includes a 16x13 matrix taking up most of the screen.
When you drag your finger across the matrix, every column will have one row selected based on your finger position.
So far so good:

  • created a Component that draws the matrix grid
  • have 16 child components to indicate the selection
  • I’m using overrides of mouseDown, mouseDrag, mouseUp to track the position of the mouse / finger and update the selection based on the current mouse event position.

However, I’m experiencing really laggy mouse handling in Juce, as I move my finger across the screen faster it’s pretty common not one mouse event is sent for full columns being 50-100px wide.
Somehow mouse events are slow and too sparse with large intervals between them.

I’m running this on a brand new Nothing Phone with 8 gigs of ram and a modern Snapdragon processor.

I did the same app natively on iOS and didn’t even have to go into any type of optimization, it was just working fine even on 8 years old devices.
Touch events were extremely reliable and precise with new events coming in on 1-2 pixel movement changes.

Do you have any tips on optimizing this, I’m running out of ideas on what to try and considering getting rid of JUCE completely and go with Flutter. The interaction and responsiveness is just that awful.

Btw, having no multi touch support is also an issue, but for now I can live with that.

Edit: Here’s a video running the app on the device: Dropbox - juce-android-laggy-touch-handling.mov - Simplify your life

No, that’s not normal. You should be able to get such an app to work perfectly using JUCE, even on relatively old Android devices.

Are you using openGL? If not, try creating an OpenGLContext and attach it to the MainWindow (but do this just for your Android build, on iOS performance is normally better without), and test using a release build.

Other than that, without seeing some code people won’t be able to help much, I’m afraid.

Also, what do you mean that there is no multi touch support?

Thanks for the response.

Do you have any links or an example on using OpenGLContext in JUCE?

Found this thread but people have mixed results:

I’m looking at the OpenGL demo app from Projucer examples to learn more. To be continued.

That thread is over six years old! Many things have improved since. It’s very simple, on your main window or main component just declare your context:

#if JUCE_ANDROID
    OpenGLContext openGLContext;
#endif

and in the constructor attach it:

#if JUCE_ANDROID
    openGLContext.attachTo (*this);
#endif

That’s it!

1 Like

That should already make a big difference. No need to get into actual openGL programming.

1 Like

Perfect.
This made a world of a difference, now it’s really smooth. Thanks for the help and the prompt response.
For completeness and future reference for others I had to add the juce_opengl module in Projucer.

1 Like

Great!