15

I am using ondragListener for view drag . My root is viewgroup with more viewgroup containers into the root and am adding views like imageview/textview inside the containers .

If I use the only container(ViewGroup) like linearlayout for drag and drop its working fine but if I start adding views like imageview inside these containers and still dragging point is containers only holding this view.

onActionDrop gets an stackoverflow error : stack size 8MB.

onActionDrop code is :

if (e.getAction()==DragEvent.ACTION_DROP) {
        final View view = (View) e.getLocalState();
        final ViewGroup from = (ViewGroup) view.getParent();
        from.removeView(view);
        final LinearLayout toView = (LinearLayout) v;
        toView.addView(view);}

Error Logs :

 java.lang.StackOverflowError: stack size 8MB
    android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:6546)
    android.os.TransactionTooLargeException: data parcel size 26840220 bytes
android.os.BinderProxy.transactNative(Native Method)
android.os.BinderProxy.transact(Binder.java:503)
android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4425)
com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:90)
java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
Nikhil
  • 3,711
  • 8
  • 32
  • 43
Night Owl
  • 211
  • 2
  • 6
  • Is this a full stacktrace? – Tin Tran Oct 03 '16 at 14:04
  • 1
    Your code seems right but the problem may be with the amount of visual components you´re moving from one container to the other, you may need to destroy and recreate the dragged view or something like that. Please see this other issue http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception – eduyayo Oct 05 '16 at 08:50
  • @TinTran Yes this is it. – Night Owl Oct 05 '16 at 13:09
  • Can you show the full code, where you assign the `DragListener` to the `Views`, and the code for the `DragListener` itself? – yshahak Oct 06 '16 at 07:47
  • I think you may have a cycle in your View hierarchy. A stack overflow on `resetResolvedLayoutDirection` often indicates this. This can happen for a variety of reasons (many documented here at SO if you search), depending on how you create/inflate them. – Turix Nov 01 '17 at 05:04

1 Answers1

0

I think you should be looking at the TransactionTooLarge exception instead of the StackOverflow one. TransactionTooLarge can sometimes be a hard one to track down but usually it has something to do with too much data being sent between Activity/Fragment or stored in savedInstanceState. As pointed out by @eduyayo in a comment above, you could take a look at this post:

What to do on TransactionTooLargeException

I experienced a similar error a while back and it was due to a huge list was being passed from an Activity to a Fragment and the crash itself occurred in a completely random place.

patrick.elmquist
  • 2,113
  • 2
  • 21
  • 35