Jump to content

Hi,

 

I have solved the issue, This more of a warning than anything else. 

 

So, here we go. When developing an app, I typically just install the app to my phone (LG E971 or LG Optimus G) and debug from there. The issue of VelocityTracker.recycle() appeared literally as I was about to push the app out the door to friends that requested it.

 

So heres the issue: (assume all code shown functions as expected on  android 4.4 and below. "...." indicates a removal of code to keep to the topic.

 public boolean onTouchEvent(MotionEvent mv) {        int id = mv.getActionIndex();        int act = mv.getActionMasked();        int pointer = mv.getPointerId(id);        switch (act) {            case MotionEvent.ACTION_DOWN:            ....            case MotionEvent.ACTION_CANCEL:                    mVelocityTracker.recycle();                    break;        }

As you notice VelocityTracker.recycle() is called in the case of MotionEvent.ACTION_CANCEL. Now its completely possible for this case to happen twice in a row, on non-5 flavors of android, no exception will be thrown, it will behave as if it just ignored the second calling of .recycle(). 

 

Now, on android 5, if the .recycle() is called twice, it will throw the "IllegalStateException" claiming that the the memory has already been added to the pool.

 

The solution:

Super simple:

             //trycatch to fix android 5 only bug. FFS.                try {                    mVelocityTracker.recycle();                    break;                }   catch(IllegalStateException e)  {break;}

Conclusion:

No idea why there was a behavior change, nor do I care; it may just be a bug in Android 5. I made this post for those who maybe very confused at what is happening to their app on very specific versions of android. 

Java tuts:


Constructors, possibly more to come.


221 Goodbye.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×