I use the following code to drag a view from an activity to another activity within my application. Knowing that the second activity (That receives drop event) is not created / alive when the drag starts.
It works good on
Samsung Note 3 Android 5 API 21, Samsung Note 4 Android 6.0.1 API 23
but not working on
ASUS ZenPad 8.0 Android 5.1.1 API 22, Le Max 2 Android 6.0 API 23
Your thoughts are appreciated.
Starting Drag operation:
public boolean onItemLongClick(AdapterView<?> aParent, View aView, int aPos, long aID) {
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(aView);
Intent intent = prepDNDIntent();
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);
}
startMainActivity();
finishThisActivity();
return true;
}
Receiving Drop Operation
public boolean validDragNDropOperation(View aView, DragEvent aEvent){
boolean status = false;
ClipDescription clipDescription = aEvent.getClipDescription();
if (clipDescription != null && clipDescription.getLabel().toString().equalsIgnoreCase(DRAG_N_DROP_DESCRIPTION)) {
status = true;
}
return status;
}
public boolean onDrag(View aView, DragEvent aEvent) {
switch (aEvent.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
This is not called on some devices
return validDragNDropOperation(aView, aEvent, false);
case DragEvent.ACTION_DROP:
....
....
....
....
....
break;
}
return true;
}
Knowing that both Activities are set android:launchMode="standard"
from Drag and Drop not working between 2 activities on some devices
No comments:
Post a Comment