Android - How to access an Activity through a Papplet?

2

I have a class with extends PApplet and I want to migrate from it to another with extends Activity

I tried through Intent but could not.

Body of class PApplet:

public class CamMain extends PApplet {

    public void setup() {
        //ESCOPO . . .
    }

    public void draw() {
        //ESCOPO . . .
    }

    public void onCameraPreviewEvent() {
        //ESCOPO. . .
    }

    public void mousePressed() {
        //ESCOPO . . .
    }

    public void teste(){
        // CRIEI PRA TESTAR MIGRAÇÃO POR INTENT, MAS NÃO FUNCIONOU. . .
        //Intent intent = new Intent(this, Teste.class);
        //startActivity(intent);
    }
}

PApplet is called by an Activity as shown in the example below

Activity calling PApplet:

package processing.test.camMain;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.view.ViewGroup.LayoutParams;
import  android.app.FragmentTransaction;
import processing.core.PApplet;
public class MainActivity extends Activity {
    PApplet fragment;
    private static final String MAIN_FRAGMENT_TAG = "main_fragment";
    int viewId = 0x1000;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        FrameLayout frame = new FrameLayout(this);
        frame.setId(viewId);
        setContentView(frame, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        if (savedInstanceState == null) {
            fragment = new CamMain();
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.add(frame.getId(), fragment, MAIN_FRAGMENT_TAG).commit();
        } else {
            fragment = (PApplet) getFragmentManager().findFragmentByTag(MAIN_FRAGMENT_TAG);
        }
    }
    @Override
    public void onBackPressed() {
        fragment.onBackPressed();
        super.onBackPressed();
    }
}
    
asked by anonymous 28.07.2016 / 21:00

2 answers

0

I achieved this way:

Intent intent = new Intent(this.getActivity(), Teste.class);
try {
    this.finalize();
} catch (Throwable throwable) {
    throwable.printStackTrace();
}
this.startActivity(intent);
    
29.07.2016 / 20:46
0

Speak Cristian,

Have you tried with the startIntent ? example:

Intent intent = new Intent(this, Teste.class);
startIntent(intent);

Hugs.

    
28.07.2016 / 22:28