拖放在某些设备上的两个活动之间无法正常工作

Jac*_*ack 6 android drag-and-drop

我使用以下代码将视图从活动拖到我的应用程序中的另一个活动.知道第二个活动(收到掉落事件)在拖动开始时没有创建/活动.

它很好用

三星Note 3 Android 5 API 21,三星Note 4 Android 6.0.1 API 23

但没有工作

华硕ZenPad 8.0 Android 5.1.1 API 22,Le Max 2 Android 6.0 API 23

你的想法很感激.

开始拖动操作:

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;
}
Run Code Online (Sandbox Code Playgroud)

接收丢弃操作

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;
}
Run Code Online (Sandbox Code Playgroud)

知道我将两个活动设置为android:launchMode ="standard"和"singleTask",但我以相同的结果结束.

编辑

在测试期间,我使用了一个AlertDialog来保存拖动的视图(而不是使用活动),并且我遇到了同样的问题,当将视图从AlertDialog拖动到Activity(拥有AlertDialog)时,ACTION_DRAG_STARTED没有被调用.