startDrag(android.content.ClipData, android.view.View.DragShadowBuilder, java.lang.Object, int)
is deprecated. How to solve this without losing compatibility to the older versions? Are there any alternatives? I'm learning android basics and while trying out a simple drag and drop exercise, I encountered this error.
According to Androids API reference startDrag()
was deprecated in API level 24
Use startDragAndDrop()
for newer platform versions.
And since Android API level 24 equals Android N you can use:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
view.startDragAndDrop(...);
} else {
view.startDrag(...);
}
startDrag
was very recently deprecated - in API 24. So you could use startDragAndDrop
instead and differentiate between versions.
What you could also say is preserving compatibility to lower versions. The thing is Drag&Drop was introduced in API 11. So you could try differentiating between versions:
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
//MyDragEventListener comes in here
}
Otherwise as said, there is no official Drag&Drop for < API 11. There is not much use of implementing it for Android below API 14 (or API 15 for that matter), because per Android Studio, there are only a handful of devices running below that version, i.e. only mere 2.3%.
If you still, insist on doing it, you could use a third party library such as Android-DragArea.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With