I\'m trying to access the the assets in native code from a custom WallpaperService. The native code compiles and works but trying to get the AAssetManager reference from th
Read the comments inside asset_manager_jni.h: "Note that the caller is responsible for obtaining and holding a VM reference to the jobject to prevent its being garbage collected while the native object is in use."
In Java, you are passing an object (mgr) that may be freed by the garbage collector once the native callback is called. To prevent this, you could, for example, create the mgr variable as a private attribute in your class and then pass it through the load method, such as this:
private static native void load(AssetManager mgr);
private AssetManager mgr;
@Override
public void onCreate() {
super.onCreate();
mgr = getResources().getAssets();
load(mgr);
}
Also, I think you must replace your native C++ callback with:
void Java_com_example_android_livecubes_cube1_CubeWallpaper1_load
(JNIEnv *env, jobject obj, jobject assetManager)