setSimulateMouse resetting to true

In my app I have simulate mouse set to false. If I hit the home button, then start the app it resumes successfully but simulate mouse has been set back to true.

I haven’t been able to track down what is resetting this on resume. I tried setting it back to false in the gainFocus function in Main but trying to access the inputManager at this point throws an exception.

Anyone have any suggestion?

I cannot see the exception.

[java]@Override
public void gainFocus(){
super.gainFocus();
if(this.getInputManager() != null)
{
this.getInputManager().setSimulateMouse(false);
}
}[/java]

The issue is that getInputManager() always returns null so I can’t use the gainFocus function to set mouse simulation back to false, since it is initially set to false in the initialization of an AbstractAppState.

Basically I want to make sure that this is set to false on focus/resume but I’m not sure how.

Never fails that I find a solution after posting about an issue. Noticed in the MainActivity that I still had mouseEventsEnabled set to true. I’m guessing this was overriding the settings in my code on resume because after setting it to false the value remained false after going to the home screen.

1 Like
@Aquanaut81 said: [java]@Override public void gainFocus(){ super.gainFocus(); if(this.getInputManager() != null) { this.getInputManager().setSimulateMouse(false); } }[/java]

The issue is that getInputManager() always returns null so I can’t use the gainFocus function to set mouse simulation back to false, since it is initially set to false in the initialization of an AbstractAppState.

Basically I want to make sure that this is set to false on focus/resume but I’m not sure how.

Well, the above code should have prevented an exception since you specifically check for null… and anyway, after the app has started getInputManager() should not return null.

I thought the same thing and that was why I didn’t originally have the null check. Without it I was get the following:

[java]E/AndroidRuntime(30402): FATAL EXCEPTION: main
E/AndroidRuntime(30402): java.lang.RuntimeException: Unable to resume activity {com.mycompany.mygame/com.mycompany.mygame.MainActivity}: java.lang.NullPointerException
E/AndroidRuntime(30402): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2929)
E/AndroidRuntime(30402): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2958)
E/AndroidRuntime(30402): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2364)
E/AndroidRuntime(30402): at android.app.ActivityThread.access$700(ActivityThread.java:165)
E/AndroidRuntime(30402): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
E/AndroidRuntime(30402): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(30402): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(30402): at android.app.ActivityThread.main(ActivityThread.java:5455)
E/AndroidRuntime(30402): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(30402): at java.lang.reflect.Method.invoke(Method.java:525)
E/AndroidRuntime(30402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
E/AndroidRuntime(30402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/AndroidRuntime(30402): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(30402): Caused by: java.lang.NullPointerException
E/AndroidRuntime(30402): at mygame.Main.gainFocus(Main.java:58)
E/AndroidRuntime(30402): at com.jme3.app.AndroidHarness.gainFocus(AndroidHarness.java:603)
E/AndroidRuntime(30402): at com.jme3.app.AndroidHarness.onResume(AndroidHarness.java:338)
E/AndroidRuntime(30402): at com.mycompany.mygame.MainActivity.onResume(MainActivity.java:40)
E/AndroidRuntime(30402): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1209)
E/AndroidRuntime(30402): at android.app.Activity.performResume(Activity.java:5450)
E/AndroidRuntime(30402): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2919)[/java]

Weird. That makes me wonder if the input manager is recreated every time the activity is resumed or something.