After ontouch, it can't go ondrag on Android
<p>(I deleted all code, because the below code is not working either.)</p>
<h3>Additional information and short summary - the real problem</h3>
<p>This is interesting. I have another project a simple activity. There, I can drag. Now in this project, I block commented everywhere. There are only a few lines, like another project, but still no drag.</p>
<pre><code> Drag is in progress, but there is no drag window handle.
</code></pre>
<p>Sometimes it says. I also searched it, but I could not do it.</p>
<p>The code is now:</p>
<pre><code>protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, &quot;matching ggame OnCreate&quot;);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_matchgame);
    setupForGame();
    Log.d(TAG, &quot;matching game OnCreate ends&quot;);
}//oncreate end

void setupForGame(){
    Log.d(TAG, &quot;matching game setupforgame&quot;);

    imageAnswer = (ImageView) findViewById(R.id.imgAnswer);

    imageAnswer = (ImageView) findViewById(R.id.imgAnswer);
}

public boolean onTouch(View view, MotionEvent motionEvent) {
    Log.d(TAG, &quot;ontouch never&quot;);
    if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
        ClipData data = ClipData.newPlainText(&quot;&quot;, &quot;&quot;);
        View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
        view.startDrag(data, shadowBuilder, view, 0);
        view.setVisibility(View.INVISIBLE);
        return true;
    }
    else {
        return false;
    }
}

@Override
public boolean onDrag(View receivingLayoutView, DragEvent dragEvent) {
    Log.d(TAG, &quot;ondrag start&quot;);
</code></pre>
<p>And still not going inside.</p>
<p>I made it static to see if that is the problem.</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    android:paddingLeft=&quot;@dimen/activity_horizontal_margin&quot;
    android:paddingRight=&quot;@dimen/activity_horizontal_margin&quot;
    android:paddingTop=&quot;@dimen/activity_vertical_margin&quot;
    android:paddingBottom=&quot;@dimen/activity_vertical_margin&quot;
    android:id=&quot;@+id/relative_layout&quot;
    tools:context=&quot;.games.MatchingGame&quot;&gt;

    &lt;ImageView
        android:id=&quot;@+id/imgAnswer&quot;
        android:layout_width=&quot;111dp&quot;
        android:layout_height=&quot;111dp&quot;
        android:src=&quot;@drawable/b3_1&quot;
        android:layout_alignParentLeft=&quot;true&quot;
        android:layout_centerInParent=&quot;true&quot;
        /&gt;

&lt;/RelativeLayout&gt;
</code></pre>
<p>It is same as another project, but it is not working. I looked at all possibilities and debugged.</p>
<p>And please don't ask for drag method code; it is not important. It can't enter it.</p>
<p>When I hold and drag image, this comes to the log in a loop until I leave:</p>
<pre><code>I/SPRDHWComposer: util[1759] warning: osdLayer width 111, stride 112, not equal!
</code></pre>
<p>And when I leave the image:</p>
<pre><code>V/WindowManager: rotationForOrientationLw(orient=0, last=1); user=0 USER_ROTATION_LOCKED sensorRot
V/WindowOrientationListener: getProposedRotation : mEnabled = false, mUsedautorotioansensor =true
 W/WindowManager: Drag is in progress but there is no drag window handle.
</code></pre>
<p>I also made this if the touch is problem, but it is still the same:</p>
<pre><code>imageAnswer.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        //if (event.getAction() == MotionEvent.ACTION_DOWN) { Log.d(TAG, &quot;ontouch down&quot;);

        //Log.d(TAG,&quot;parent &quot;+ String.valueOf(img1.getParent()));
        Log.d(TAG, &quot;view &quot;+String.valueOf(v));

        ClipData data = ClipData.newPlainText(&quot;&quot;, &quot;&quot;);
        View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
        v.startDrag(data, shadowBuilder, v, 0);
        v.setVisibility(View.INVISIBLE);
        return true;
</code></pre>
<p>This is my old project that works with drag and drop. I can't see the difference:</p>
<p><a href="https://gist.github.com/anonymous/540a70e05de6d765e20896b47deb7eb2" rel="nofollow noreferrer">https://gist.github.com/anonymous/540a70e05de6d765e20896b47deb7eb2</a></p>
<p>When I do this</p>
<pre><code>imageAnswer.setOnDragListener(new View.OnDragListener() {
    public boolean onDrag(View v, DragEvent event) {  Log.d(TAG, &quot;drag&quot;);

        return false;
    }
});
</code></pre>
<p>It does not work either. No log.</p>
<p>Also this does not give a log:</p>
<pre><code>imageAnswer.setOnDragListener(new dropListener());

private class dropListener implements View.OnDragListener {

    @Override
    public boolean onDrag(View v, DragEvent event) {Log.d(&quot;Chic&quot;,&quot;ondrag&quot;);
        switch (event.getAction()) {

            case DragEvent.ACTION_DRAG_STARTED:
                break;

            case DragEvent.ACTION_DRAG_ENTERED:
                break;

            case DragEvent.ACTION_DRAG_EXITED:
                break;

            case DragEvent.ACTION_DROP:
                break;

            case DragEvent.ACTION_DRAG_ENDED:
                break;

            default:
                break;
        }
        return true;
    }
 }
</code></pre>
<p>There is difference between the two projects:</p>
<p><a href="https://i.stack.imgur.com/HC77W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HC77W.png" alt="Differences between projects" /></a></p>
<p><strong>Can this be the reason?</strong></p>
<p>I tried also to put all setondrag setontouch inside oncreate.</p>