Note that there are some explanatory texts on larger screens.

plurals
  1. POdrag and drop in android 3.x causes illegalStateException after small number on drags
    primarykey
    data
    text
    <p>there's a problem with drag and drop mechanism at android 3.x : after doing some drags (say 30 drags) an exception accrues (see the attached link)</p> <p><a href="https://groups.google.com/forum/#!msg/android-platform/2APvO248NNY/rKI-5dCT8XcJ" rel="noreferrer">https://groups.google.com/forum/#!msg/android-platform/2APvO248NNY/rKI-5dCT8XcJ</a> (I'm getting in log the same thing as attached to that post..)</p> <p>android technician answers there that it's bug in the API, and says the only way to avoid the problem is to call Garbage Collector. </p> <p>I did it. the exception not been thrown anymore, but after a while (say more 30-40 drags) android stops calling the drop event from some reason.</p> <p>I tried to "refresh" all view by release all resources/canvas/drawing cache/recycling bitmaps and re-create them and it didn't helps (didn't throw the exception anymore - but still after some drags the drop event don't work) </p> <p>the only thing that "helps" is close the activity and restart it again.</p> <p>anyone solved this problem somehow, or have a good simple alternative??? (beside implement my own drag and drop functionality..)</p> <p>I would like to get solution that won't force me to restart or re-create anything that don't suppose to..</p> <p>here is <strong>sample code</strong> that demonstrate the bug (not demonstrates the part which I said about the problem with the drop event after using the System.GC) :</p> <pre><code>public class DragandDropExampleActivity extends Activity { private boolean mIsBeenDragged = false; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final ImageView imageViewToDRag = (ImageView) findViewById(R.id.image_view_to_drag); imageViewToDRag.setClickable(true); imageViewToDRag.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { mIsBeenDragged = true; DragShadowBuilder shadowBuilder = new DragShadowBuilder(imageViewToDRag); imageViewToDRag.startDrag(null, shadowBuilder, imageViewToDRag, 0); } else if (event.getAction() == MotionEvent.ACTION_UP) { mIsBeenDragged = false; } return false; } }); } } </code></pre> <p>this is the xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_frame" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;ImageView android:id="@+id/image_view_to_drag" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" &gt; &lt;/ImageView&gt; </code></pre> <p></p> <p>this is the stack trace:</p> <pre class="lang-none prettyprint-override"><code>06-04 13:34:32.730: E/View(8061): java.lang.IllegalArgumentException at android.view.Surface.lockCanvasNative(Native Method) at android.view.Surface.lockCanvas(Surface.java:350) at android.view.View.startDrag(View.java:11489) at com.show.dragandrop.DragandDropExampleActivity$1.onTouch(DragandDropExampleActivity.java:32) at android.view.View.dispatchTouchEvent(View.java:4617) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1291) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1291) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1291) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1291) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java: 1862) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1286) at android.app.Activity.dispatchTouchEvent(Activity.java:2315) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1835) at android.view.View.dispatchPointerEvent(View.java:4689) at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2415) at android.view.ViewRoot.handleMessage(ViewRoot.java:2077) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:132) at android.app.ActivityThread.main(ActivityThread.java:4126) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:491) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) at dalvik.system.NativeStart.main(Native Method) </code></pre> <p><strong>to make the exception accrue - just drag the image to some point on the screen, and leave the finger. repeat that exactly 30 times, and the exception is thrown. I made this very simple example, to demonstrate that the exception thrown without any overhead caused by my application.</strong> </p> <p>TIA </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload