We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am currently building an app in Android Studio involving a Processing sketch.
Main class:
import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
import processing.android.PFragment;
import processing.core.PApplet;
public class ClassMain extends Activity {
/**************************************************/
PApplet sketch;
/**************************************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.class_main);
FragmentManager fragmentManager = getFragmentManager();
sketch = new ClassSketch();
PFragment fragment = new PFragment();
fragment.setSketch(sketch);
fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
}
/**************************************************/
@Override
public void onBackPressed()
{
//ClassMain.this.finish();
}
/**************************************************/
//It doesn't work if called from sketch...
public void exits()
{
ClassMain.this.finish();
}
/**************************************************/
}
Processing Sketch:
import android.view.KeyEvent;
import processing.core.PApplet;
public class ClassSketch extends PApplet {
/*****************************************************************************/
public void settings()
{
size(displayWidth, displayHeight);
}
/*****************************************************************************/
public void setup()
{
}
/*****************************************************************************/
public void draw()
{
keykey();
}
public void keykey()
{
if(keyPressed)
{
if (key == CODED) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
//non of the following work:
//exit();
ClassMain j = new ClassMain();
j.exits();
}
}
}
}
}
Here is the problem, I want the the user, depending on some circumstances that I will add later in the sketch, to exit not only the sketch but the class that is hosting it (ClassMain
).
When ever (in the sketch) something happens in my sketch, I want to be able to exit the whole MainClass
, but I just happen to fail.
Thanks for the support.
Answers
Please link between crosposts.
This has already been answered here: http://stackoverflow.com/questions/39618629/how-to-correctly-exit-a-processing-sketch-in-android/39621083
Thank you so much.