Android - How to access an Activity through a Papplet?

Asked

Viewed 79 times

2

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

I tried through a Intent but I couldn’t.

Body of the Papplet class:

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 that calls 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();
    }
}
  • What this builder expects is a context. Without seeing the rest of the class that contains this code, you can’t know if it was meant to work. Show the rest of the class, please.

  • Hello, I put the body of the rest in question.

2 answers

0


I got it this way:

Intent intent = new Intent(this.getActivity(), Teste.class);
try {
    this.finalize();
} catch (Throwable throwable) {
    throwable.printStackTrace();
}
this.startActivity(intent);

0

Fala Cristian,

You tried with the startIntent? example:

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

Hugs.

  • I tried, but he won’t take it. When I put startActivity(Intent), it does not present errors but, there in Intent Intent = new Intent(this, Test.class); in the parameters it presents error. in place of this already tried to put the name of the class.this too but it does not accept.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.