It i possible to have multiple ofApp.cpp for multiple activities.java?

#1

I have a question. It is possible to have a .cpp for each activity?
Let 's say ofAppA.h runs in activityA.java and ofAppb.c runs in activityB.java.
Talking about multiOFActivities example.

#2

Good question.

Well…

I see that the new 10.1 of has a different native loading system than the old versions. Even if you start a new ofActivity, it uses the same core oF.

In the Android concepts, whenever you start a new activity, you start a new context. But the core oF remains same. That may be a misimplementation but I don’t want to discuss on the architecture. Instead, I would discuss how to implement your need in the current architecture.

I think that the simplest (most practical) way for you may be using same ofApp.cpp, but writing code on 2 different canvasses (one for each activity), and invoking the relevant canvas from the ofApp.cpp.

A pseudo code may look like that:

ofApp::setup() {
    canvasA = new CanvasA(this);
    canvasA.setup();

    canvasB = new CanvasB(this);
    canvasB.setup();

    selectCanvas();
}

ofApp::update() {
    if (activityChanged) selectCanvas();
    currentCanvas.update();
}

ofApp.draw() {
    currentCanvas.draw();
}

ofApp::selectCanvas() {
    if (activityA) currentCanvas = canvasA;
    else if (activityB) currentCanvas = canvasB;
}

Hope I could somehow explain the sub-architecture.

1 Like
#3

canvasA what kind of variable or function is?