I want to give the user the ability to drag from one activity to another, within my app, but the drop event not detected
Starting Drag operation in the First activity:
public boolean onItemLongClick(AdapterView<?> aParent, View aView, int aPos, long aID) {
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(aView);
Intent intent = new Intent();
intent.putExtra("Phase", "Phase");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
aView.startDragAndDrop(ClipData.newIntent(DRAG_N_DROP_DESCRIPTION, intent), shadowBuilder, null, 0);
} else {
aView.startDrag(ClipData.newIntent(DRAG_N_DROP_DESCRIPTION, intent), shadowBuilder, null, 0);
}
startSecondActivity();
finish();
return true;
}
Receiving Drop Operation in the Second activity
public boolean onDrag(View aView, DragEvent aEvent) {
switch (aEvent.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
This is not called on Android 22+
break;
case DragEvent.ACTION_DROP:
This is not called on Android 22+
break;
}
return true;
}
There will be 50 points reward for the solution.
As for why onDrop isn't called, perhaps this text from the developers site explains it.
The user releases the drag shadow within the bounding box of a View that can accept the data. The system sends the View object's listener a drag event with action type ACTION_DROP. The drag event contains the data that was passed to the system in the call to startDrag() that started the operation. The listener is expected to return boolean true to the system if code for accepting the drop succeeds. Note that this step only occurs if the user drops the drag shadow within the bounding box of a View whose listener is registered to receive drag events. If the user releases the drag shadow in any other situation, no ACTION_DROP drag event is sent.