Search code examples
androidandroid-intentandroid-activityontouch

Start an Intent from onTouch


I tried starting a new activity from onTouch block but the application terminates suddenly. My code is:

public boolean onTouch(View view, MotionEvent motionEvent) {

    ....
    Intent myIntent = new Intent(context,SecondOne.class);
    myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(myIntent);
    break;
    .....
    return true;
}

Solution

  • my initial guess without seeing a log is that something is either Null or the second activity is not declared in your manifest.

    also i would say:

      Intent myIntent = new Intent(FirstOne.this,SecondOne.class);
        myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(myIntent);
        break;