How to disable multitouch on Android?

I saw that this feature was added in 3.14. But I didn’t find in cpp-test an example of using this feature…
Anyone?

See https://github.com/cocos2d/cocos2d-x/commit/ae48e0bf697619453a4f1c366bb42f323359e8ba

In your GameActivity (the one you are set up as launch activity and which is an extend of Cocos2dxActivity or GameControllerActivity) just call getGLSurfaceView().setMultipleTouchEnabled(false); in the onCreate() method. This should disable multitouch, if it was correctly implemented in 3.14.

1 Like

Thanks a lot :slight_smile:

@mars3142 @nite

it seems somethign was changed in cocos2d-x 3.16 as this method getGLSurfaceView().setMultipleTouchEnabled not causing crashes on some Android 7.0 devices .

Maybe you know something?

Do you have any useful logcat output for that crashes? Is it only crashing on Android 7.0 or also higher (8.0 and 8.1)?

Within the Java class was only one change and this was reverted: https://github.com/cocos2d/cocos2d-x/commits/v3/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java

I didn’t check the cocos cpp code for now, because without any crashlog it’s hard to find the issue.

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.games.mygame/org.cocos2dx.cpp.AppActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.cocos2dx.lib.Cocos2dxGLSurfaceView.setMultipleTouchEnabled(boolean)' on a null object reference
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
       at android.app.ActivityThread.-wrap14(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6776)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void org.cocos2dx.lib.Cocos2dxGLSurfaceView.setMultipleTouchEnabled(boolean)' on a null object reference
       at org.cocos2dx.cpp.AppActivity.onCreate(AppActivity.java:84)
       at android.app.Activity.performCreate(Activity.java:6955)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
       at android.app.ActivityThread.-wrap14(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6776)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

Okay, your Cocos2dxGLSurfaceView is null, which should be set in Cocos2dxActivity.init().

Are you able to reproduce this error? Can you check it within the debugger, why the mGLSurfaceView is null? The init is call in Cocos2dxActivity.onCreate and I hope you are calling in your AppActivity’s onCreate as first command super.onCreate. So it seems to be an timing issue.

We calling it from AppActivity Oncreate method:

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    getGLSurfaceView().setMultipleTouchEnabled(false);

    Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());

    sContext =this;
    _appActivity = this;

Like we used exactly same code in cocos 3.14 and everything was fine, then we replaced cocos2d with cocos 3.16 and got such error. Ourself we seem can’t reproduce it as it not crashing.

That’s bad, because I have no idea why this happened.

If you can’t reproduce it. Such unexpected errors often occurs after the app was in background and needs to be recreated after the system kills it. You can set in the Android Developer options, that Android don’t keep activities. Sometimes this will help to find crashes.

Activate that option, start you game, press the home button and reopen the game from the “recent menu” (not the launcher icon). Try to use it on Android 7+ devices. Do you know which devices are affected, so try this devices? - I often find errors by doing this in my Java-/Kotlin-only Android apps.