All right, I'll try to put here more information than in my first comment.
So first of all, the system is not supposed to allow this behavior, as discussed in that thread : https://groups.google.com/forum/#!topic/android-platform/d6Kt1DhCAtw
That being said, I came across this issues when willing to automate UI tests on my applications, especially for image manipulation, where I wanted to simulate fingers on the screen.
Here's a snippet that you could potentially apply to your Activity B
:
Step 1 : Pass X
and Y
coordinates of the last MotionEvent
from Activity A
to Activity B
Step 2 : Retrieve these values in Activity B
, and then apply :
private void continueScrolling(int posX, int posY) {
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[1];
MotionEvent.PointerCoords pc1 = new MotionEvent.PointerCoords();
pc1.x = posX;
pc1.y = posY;
pc1.pressure = 1;
pc1.size = 1;
pointerCoords[0] = pc1;
MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[1];
MotionEvent.PointerProperties pp1 = new MotionEvent.PointerProperties();
pp1.id = 0;
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
pointerProperties[0] = pp1;
MotionEvent event;
// send the initial touches (this seems to be to "wake up" the view, you might not need it in a non-testing context though)
event = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN, 1, pointerProperties, pointerCoords,
0, 0, // metaState, buttonState
1, // x precision
1, // y precision
0, 0, // deviceId, edgeFlags
InputDevice.SOURCE_TOUCHSCREEN, 0); // source, flags
theViewYouWantTomove.dispatchGenericMotionEvent(event);
event = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN,
1, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0,
InputDevice.SOURCE_TOUCHSCREEN, 0);
theViewYouWantTomove.dispatchGenericMotionEvent(event);
}