0

I have a drag and drop function in my app that allows a user to move card images around on the screen. This functionality was working on all devices until it was tested on a Pixel device running Android 10. Now the DragShadow of the touched object sometimes remains and leaks out of the app. The image remains on screen even after shutting down the app and even after uninstalling the app. Only a full restart of the device will clear the images.

I obviously first suspected my code but since the imageViews are disconnected from the app environment I am now suspecting something with the RunTime system of Android 10.

Any ideas would be greatly appreciated. I can post code if needed but this class is around 3000 lines so I won't be posting the whole thing.

enter image description here

usajnf
  • 522
  • 3
  • 11

1 Answers1

0

It's now recorded as a bug at Google and assigned so it's being looked into: Drag and Drop bug report

Here's a workaround that will stabilize an app so people can use it and this may even be a fully acceptable solution for some developers if they are happy with the UI changes.

Use an OnLongClickListener instead of OnTouchListener to start the drag. Originally the user could touch and drag and now they have to long click. Keep the onTouch to do some other things with the View if needed but move the startDrag stuff to the onLongClickHandler. e.g.:

public boolean onLongClick(View v) {
        //...
        // get the card ready for dragging
        DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
        shadowBuilder.getView().setAlpha(1.0f);
        // deprecated. use startDragAndDrop but need minimum SDK to be 24
        // the original position is sent as LocalState (third argument)
        if (v.startDrag(null, shadowBuilder, position, 0)) {
            // make the moving view's old position appear invisible since
            // its replaced by the drag shadow
            v.setAlpha(0f);
        }
        return true;
    }

When the startDrag was launched from onLongClick instead of onTouch the problem went completely away with no other changes. This is not a fix since it should be possible to start a drag from an onTouchListener.

usajnf
  • 522
  • 3
  • 11