后拖动少数拖拽的Andr​​oid 3.X导致IllegalStateException异常 [英] drag and drop in android 3.x causes illegalStateException after small number on drags

查看:160
本文介绍了后拖动少数拖拽的Andr​​oid 3.X导致IllegalStateException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有拖放机制,在安卓3.x的一个问题: 做一些一拖再拖(比如30拖动)异常累积后(见附件链接)

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)

<一个href="https://groups.google.com/forum/#!msg/android-platform/2APvO248NNY/rKI-5dCT8XcJ">https://groups.google.com/forum/#!msg/android-platform/2APvO248NNY/rKI-5dCT8XcJ (我越来越登录为连接到该职位同样的事情。)

https://groups.google.com/forum/#!msg/android-platform/2APvO248NNY/rKI-5dCT8XcJ (I'm getting in log the same thing as attached to that post..)

Android的技师答案的,它是在API中的错误,并表示为了避免这个问题的唯一方法是调用垃圾收集器。

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.

我做到了。例外而不是被扔了,但一段时间后(多说了30-40拖)的Andr​​oid站调用从某种原因drop事件。

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.

我想刷新所有的观点被释放所有资源/帆布/绘图缓存/循环位图,然后重新创建它们并没有帮助(没再抛出异常 - 但有些拖累下跌后仍然事件不工作)

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)

唯一的帮助是关闭的活动,并再次重新启动它。

the only thing that "helps" is close the activity and restart it again.

人解决了这个问题不知何故,或有一个良好的简单的替代??? (旁边实现自己的拖放功能。)

anyone solved this problem somehow, or have a good simple alternative??? (beside implement my own drag and drop functionality..)

我想获得的解决方案,不会逼我重新启动或重新创建任何不猜想。

I would like to get solution that won't force me to restart or re-create anything that don't suppose to..

下面是样品code,展示了这个错误(没有说明我说关于使用System.GC的后问题与放置事件的部分)

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;
        }
    });

}
}

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<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" >

<ImageView
    android:id="@+id/image_view_to_drag"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" >

</ImageView>

这是堆栈跟踪:

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)

,使异常应计 - 只是图像拖动到屏幕上的某个点,并留下手指。再说一遍,正好是30倍,而异常。 我做这个很简单的例子,以证明没有异常引起我的应用程序的任何开销抛出。

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.

TIA

推荐答案

很多过去了,我问这个问题的时间。 当安卓ICS发布 - 这个错误并没有存在了。 所以由于Android ICS真的是有针对性的蜂窝状没有理由编写应用程序。 反正只有0.3%,运行此版本的操作系统总Android设备,

a lot of time passed since I asked that question. when android ICS was released - this bug was not exists any more. so since android ICS there is really no reason writing applications targeted to Honeycomb. anyway only 0.3% of total android devices running this version of OS,

所以对我来说,答案是 - 只要不使用蜂窝! - >

so for me the answer is - just not to use Honeycomb! :->

这篇关于后拖动少数拖拽的Andr​​oid 3.X导致IllegalStateException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆