android - 拖放在某些设备上的 2 个活动之间不起作用
问题描述
我使用以下代码将视图从一个活动拖到我的应用程序中的另一个活动。知道拖动开始时第二个活动(接收放置事件)没有创建/活动。
它适用于
三星 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;
}
接收丢弃操作
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;
}
知道我将两个活动都设置为 android:launchMode="standard" 和 "singleTask"但我以相同的结果结束。
编辑
在测试期间,我使用了一个 AlertDialog 来保存被拖动的视图(而不是使用活动),并且我遇到了同样的问题,当将视图从 AlertDialog 拖动到 Activity(拥有 AlertDialog)时,没有调用 ACTION_DRAG_STARTED。
解决方案
推荐阅读
- sql-server - 在Entity Framework中配置模型时ForSqlServerHasIndex和HasIndex有什么区别
- python - 有没有办法在 azure python sdk api 中获取 vm 的 vcpu 数量?
- r - R 中 sqldf 中的 min(date) 未转换为日期格式
- hibernate - 带有谓词的条件生成器
- uipath - 如何使用带有 UIPATH 的 Excel 迭代 SAP 表并单击每一行?
- javascript - 是否可以在 TypeScript 中使用类型化流?
- jenkins - 在管道中使用 Jenkins 全局凭证 (Jenkinsfile)
- laravel - 向数据表显示年龄 laravel
- android - Android中简单跟踪器的正确方法?
- qt - Qt qml 错误“无法将 [未定义] 分配给 QDeclarativeGeoMapType*”