Android life cycle - Solved

Hi all,

I am using OF 0.9.1, and have an app with a native Android front-end. The app sets a reference to the activity’s instance in the onCreate method as follows:

OFActivity instance;
public void onCreate(Bundle savedInstanceBundle) {
    instance = this;

// callback from ofApp after it's initialised. 
public void callbackOnLoad(String data) {
    instance.runOnUiThread(new Runnable() {
         // data arrived, populate in widgets & set visibility

This works perfectly fine the first time around (initial app load). However, if the app is put in background mode where onDestroy() is triggered (this happens every time with the back button on my device), the “instance” variable still references the old (ofActivity) object in the callbackOnData.

Note: “onCreate” is called when the app is resumed, and I can see the instance variable getting updated before:

ofApp = new OFAndroid(getPackageName(), this); 

is called.

Appreciate any help or pointers!


The issue was global JNI refs that got instantiated during object creation in many classes on the c++ side. I hooked in a call to reload these refs in the “reloadTextures” callback, and all is well again.