# Touch handling is extremely laggy on Android

**URL:** <https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564>\
**Category:** Android\
**Created:** [August 11, 2022, 10:53am UTC](https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564 "2022-08-11T10:53:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmri](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rmri/32/10494_2.png) [@rmri](https://forum.juce.com/u/rmri)\
**Post date:** [August 11, 2022, 10:53am UTC](https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564/1 "2022-08-11T10:53:59Z")

</div>

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.

 ![Screenshot_20220811-124622](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/5/5e42fa555d4b46692433868098a5c17ea49819f2.png)

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](https://www.dropbox.com/s/xc91g75yr48nvag/juce-android-laggy-touch-handling.mov?dl=0)

---

<div class="post-metadata">

**Author:** ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)\
**Post date:** [August 11, 2022, 11:10am UTC](https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564/2 "2022-08-11T11:10:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rmri](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rmri/32/10494_2.png) [@rmri](https://forum.juce.com/u/rmri)\
**Post date:** [August 11, 2022, 11:31am UTC](https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564/3 "2022-08-11T11:31:24Z")

</div>

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:

> [@Opengl render in android](https://forum.juce.com/t/opengl-render-in-android/12968/7):
>
> So, I tested the time between touch events (via Java log) on mouseDrag (ACTION\_MOVE)&nbsp;and its averaging around&nbsp;70-85ms. I'm not sure why its so slow. I'm digging around to see if there's anything that can be done on the Java side.&nbsp; UPDATE:&nbsp;Testing on an HTC Desire, with OpenGL switched on (via attachTo on topLevelComponent) I get crazy graphical glitches appearing. Same APK runs fine on a Samsung Galaxy Ace 2.&nbsp;I've switched back to software rendering for now, as I think my performance issues ste…

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

---

<div class="post-metadata">

**Author:** ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)\
**Post date:** [August 11, 2022, 11:55am UTC](https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564/4 "2022-08-11T11:55:10Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)\
**Post date:** [August 11, 2022, 11:57am UTC](https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564/5 "2022-08-11T11:57:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rmri](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rmri/32/10494_2.png) [@rmri](https://forum.juce.com/u/rmri)\
**Post date:** [August 11, 2022, 12:02pm UTC](https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564/6 "2022-08-11T12:02:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aamf](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aamf/32/19941_2.png) [@aamf](https://forum.juce.com/u/aamf)\
**Post date:** [August 11, 2022, 12:11pm UTC](https://forum.juce.com/t/touch-handling-is-extremely-laggy-on-android/52564/7 "2022-08-11T12:11:42Z")

</div>

Great!
