Open a Second Android Activity while drawing in GestureOverlayView?

47 views Asked by At

I have a MainActivity2 that implements OnGesturePerformedListener, but I cannot start a second activity. What am I missing?

public class MainActivity2 extends Activity
        implements OnGesturePerformedListener
{
    private GestureLibrary gestureLib;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_activity2);

        gestureLib = GestureLibraries.fromRawResource(this, 
                R.raw.gestures);
        if (!gestureLib.load()) {
            finish();    
        }
        GestureOverlayView gestures = (GestureOverlayView) 
                findViewById(R.id.gestureOverlayView);
        gestures.addOnGesturePerformedListener(this);
    }

    @Override
    public void onGesturePerformed(GestureOverlayView overlay, 
            Gesture gesture) {    
        ArrayList <Prediction> predictions = gestureLib.recognize(gesture);

        if (predictions.size()>0) {
            Prediction prediction = predictions.get(0);
            if (prediction.score>1.0) {
                if (prediction.name.equals("One")) {
                    Intent intent = new Intent(
                            MainActivity2.this, 
                            MainActivity3.class);
                    startActivity(intent);
                }

                if (prediction.name.equals("Two")) {
                    Intent intent = new Intent(
                            MainActivity2.this,
                            MainActivity4.class);
                    startActivity(intent);
                }
            }
        }
    }
}
0

There are 0 answers