0

I am trying to pass "message" string to MainActivity using intent, I tried everything but still no luck. Can you help me through this.

public class MoveMouse {

public boolean onTouchEvent(MotionEvent event) {
    int eventaction = event.getAction();

    switch(eventaction) {
        case MotionEvent.ACTION_MOVE: {
            // new position
            final float x = event.getX();
            final float y = event.getY();

            //  get delta
            final float deltax = x - this.lastX;
            final float deltay = y - this.lastY;
            // set last position
            this.lastX = x;
            this.lastY = y;

            String message = (deltax + "," + deltay);
            //intent
            Intent ins = new Intent(this,MainActivity.class);
            ins.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            ins.putExtra("mv", message);
            this.startActivity(ins);
Navneet Singh
  • 11
  • 1
  • 3

1 Answers1

0

Your MouseMove class is not a Context such as an Activity so using this where a Context is required won't work.

There isn't enough context (sic) in the question to tell how you should be passing the Context, but consider passing one as an argument when instantiating your MouseMove.

laalto
  • 150,114
  • 66
  • 286
  • 303