In Android, using JNI in my Java application, I need ANativeActivity to manage resources. My problem is that I have not:
void android_main(struct android_app* state)
because I just call some functions using JNI. Usually people use_
void android_main(struct android_app* app)
{
struct engine engine;
ANativeActivity* activity = app->activity;
std::string mApkWorkspacePath = activity->internalDataPath;
AAssetManager* mApkAssetManager = activity->assetManager;
}
To get that values from the struct. How can I have the ANativeActivity manually?
this thread is a little old but I've recently been trying to work out the same issue, having some older NDK code that I'm freshening up and having found that all the NDK examples aren't much use to me due to their use of these new structures. I thought I'd pass on my findings here, as it's not all that clear from the documentation and for people approaching the problem from this angle.
The NDK now features a series of helper classes (named 'NativeActivity') to make NDK development easier - I suspect we're both doing the same sort of things as these helpers do, in our own older code.
The 'ANativeActivity' C++ structure refers to one structure that's new to this portion of the SDK. It's defined in and refers back to the Java object 'NativeActivity' that's the class your activities derive from using the new (as of 2015 anyway) helper functions and classes.
As such, there's no way to get at this object using 'raw' NDK calls: it doesn't exist for apps that doen't use that part of the NDK. You can however look at the source code (see 'NativeActivity.java' and 'android_app_NativeActivity.cpp') and replicate it's functionality using raw NDK calls, or you can switch to using the helper application model instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With