Android Project Cheat Sheet

@nehon said: @t0neg0d for saving the game, we have a SaveGame class that deals with this kind of things

It saves a Savable so basically it can save a Node as you did, but you can also have your own class that implements savable.

The major advantage over your way is that it seamlessly work on desktop and on android.

Unfortunately, it doesn’t work on android as it is not saving to a place that all devices recognize as valid.

SaveGame would need to be modified with the first bit of info above… then it should be gtg.

More specifically:

File daveFolder = new File(JmeSystem.getStorageFolder().getAbsolutePath() + File.separator + gamePath.replaceAll("/", File.separator));

doesn’t return a path that the apk has permissions to write to. =(

Well I’ll look into how I do it because it’s how I save the game in stack3D and never had any issues.

@nehon said: Well I'll look into how I do it because it's how I save the game in stack3D and never had any issues.

Actually, this would work prior to a target version of 4 or greater I believe, that is when the read/write permissions were limited to the apk specific folders. WSo SaveGame only works if you don’t plan on using Google Play Services, or Play Games Services, or integrating Facebook, etc, etc

oh ok. yeah I don’t use any of those…
Well maybe SaveGame could be enhanced for this purpose.


This should be covered by the getStorageFolder() method then. (I am not saying it is)

@normen said: This should be covered by the getStorageFolder() method then. (I am not saying it is)

JmeSystemDelegate calls:

storageFolder = new File(System.getProperty(“user.home”), “.jme3”);

System.getProperty(“user.home”) returns an empty string depending on the build target.

Not sure if this is expected or not… guess it’s time for me to go do some reading!

EDIT: Ah, this was reported and patched by @iwgeric in this thread:

Anyone know if this was applied?

Well, I am doing the following for both android and PC and it works perfectly:

[java]File folder = JmeSystem.getStorageFolder();[/java]

Hope it helps.
On android this will be the folder: root/android/data/<package_name>/files/<file_to_save>

what dimensions should i uses for the splash screen picture? couldn’t it potentially come out weird as various devices have different aspect ratios?

Sorry for reviving an old thread, but I was wondering if anyone could help me out with establishing communication between the main application and the android side.

At the moment, I am just trying to call a simple method which will display a toast message when a Nifty GUI button is pressed.

I have followed the steps above, creating a JmeToHarness Interface, with a single method called toast, but each time I try and test it, nothing happens and I get the following error:

“WARNING Root Cause: java.lang.NullPointerException: Attempt to invoke interface method ‘void mygame.JmeToHarness.toast()’ on a null object reference”

I appreciate any help you can give. I’m relatively new to both Java and jme3, and so far I’ve been able to pick things up but I’ve been stuck on this one for a while now.

You can create an AppState in the MainActivity

My current projects only use this to pass over the Android Files Directory.

Previously I used this to tell the MainActivity when to display interstitial ads.

I got the interface working in the end, then it stopped working when I moved everything over to 3.1. Just in case anyone else is having the same problem, to use this method in 3.1 you need to create a private variable to hold the instance of the Main fragment. I found that @iwgeric has done this in the jME-Android-Examples project GitHub - iwgeric/jME3-Android-Examples: An Android Studio project that provides a set of example jMonkeyEngine3 applications. (thanks for that, it confirmed that I wasn’t trying to do something stupid).

Communication Between your Application & Main Activity in 3.1

  1. Follow the above steps to create the JmeToHarness interface from @t0neg0d

  2. In MainActivity, Create a private variable of type Main to hold the instance of the app:
    private Main mainApp;

  3. In the onCreate method, after the “find the fragment” code, add the following:
    mainApp = (Main)jmeFragment.getJmeApplication();

I found that after I did this everything was working as expected.