问题
I have created my own custom view class by extending "SurfaceView." I then override the onTouchEvent method. Two questions.
(1) Should I even both calling the super.onTouchEvent even though I handle everything (I think) I need? (2) Should have the work done in a new thread? I am receiving many Skipped 32 frames! The application may be doing too much work on its main thread Is the onTouchEvent called from the UI thread?
My view is nothing more than a joy stick and on the on touch event I simply move the coordinates of an object with 3 or 4 lines of code.
回答1:
Here it is not necessarey to call superOnTouchEvnet.But remember that if you return false it wont work. so it is better to return super.OnTouchEvent after finishing task if you want to handle the event. If for some casees or for some input you dont want to handle the touch event then without using the super method just return false.
yes. this method is handled by main UI thread. so for long tasks use any safe methods like using different threads, asynctask or handler.post.
来源:https://stackoverflow.com/questions/13465911/android-ontouchevent-work