The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDLActivity NDK communicating with C++.
Timodor


Joined: 14 Apr 2013
Posts: 72
Location: Australia
I know this might be out of scope but I don't know who has experience with SDLActivity and calling ad's when C++ code is certain state.

I want to call ads if a bool is true, disable the ad when the bool is false.
SDLActivity NDK communicating with C++.
Michael Labbe
Guest

You can call into Java code using the JNI.  The JNI requires a JNIEnv ptr and possibly an activity class or possibly an object.  You can access these via SDL:

https://wiki.libsdl.org/SDL_AndroidGetJNIEnv



Note that you are on the game thread and not your UI thread when running your native code.  Depending on how your Ad SDK is set up, this may cause concurrency issues which you must address.  The Android Readme explains the threading situation.


You can get blocks of Java code to run on the ui thread by using runOnUiThread.  It is a well documented thing across the web, used in more Android places than just SDL game development.


Michael Labbe

On Mon, Feb 1, 2016 at 4:47 PM, Timodor wrote:
Quote:
I know this might be out of scope but I don't know who has experience with SDLActivity and calling ad's when C++ code is certain state.

I want to call ads if a bool is true, disable the ad when the bool is false.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

...
Timodor


Joined: 14 Apr 2013
Posts: 72
Location: Australia
Thanks for this information, I did get working using your information. With Help of Friend all we had to do was create a Java Function in SDLactivity.java and it worked. But Still having bugs with the threads.