Android dispatchTouchEvent, onTouchEvent, onTouch stop working after 1-5 minutes - android

I develop OpenGL ES 2.0 (GLSurfaceView) android game. Touch events stop working after sometime 1-5 minutes. I do not add any subviews. I have ad networks integrated but internet is turned off.
First I implemented onTouch method from OnTouchListener interface. Then I implemented onTouchEvent in GLSurfaceView and later dispatchTouchEvent
All these method get called for the first few minutes but stop get called. It is not related to game play.
What may course these issues?
I wrapped code in onTouch with try/catch block and put breakpoint in catch to ensure there is no exception in that method.

If you lock the UI thread then it will block touch but will not block GL thread. It will also block runOnUiThread calls.

Most likely there is something intercepting, and consuming the touch event that is "above" your surface view. I wonder if your ad network is perhaps displaying some sort of invisible ad? (invisible because there is no network?). Do you see the problem when you remove the ad network?

Related

where to put infinite loop in android app to handle tweens

I would like to make use of the universal tween engine in my pure android app, and understand that I will need to put a loop somewhere which will update the tweenmanager every frame. I have used this before in game projects where i have access to the game loop provided but in the case of a pure android application, where would I create this loop and what is the best way to handle this as my app is opened/closed/paused/resumed etc?
Am I best creating a new thread in the onResume method for each activity and starting the loop there and ending the loop in the onPause method? or is it better to create a class that acts as a sort of "Activity manager" and is always available? if so how would I do this?
I found some useful documentation on this at https://code.google.com/archive/p/java-universal-tween-engine/wikis/AndroidUI.wiki and It seems the 'correct' way to achieve this is to create a new loop for each activity in onResume() and end the loop in onPause()
There is an API available starting in API level 16 called Choreographer. This is the thing that keeps the main thread pumping events at 60 frames per second. You can register a callback to be executed with the next frame, then within that callback, register to run it again at the next frame. This is the most reliable way to get called at every frame with near-perfect timing (as long as the main thread is not being blocked in a way that would case frame loss).
Your callbacks will all be called on the main thread, so be careful yourself about blocking the main thread. So keep your work super fast.

why the interval of invoking applyTransformation() is about 16ms?

recently, I am researching the system implement of android.view.animation.Animation.
I override the Animation.applyTransformation() method, and log the invoking interval time, it's about 16ms.
16ms' interval means 60fps. This make the animation plays smoothly.
But why is 16ms? Who control this?
If I implement a animation thread to implement custom animation, I usually do postDelayed(this, 16), so that my Thread will run at 60fps, each time post a message to Handler ,tell it to do some UI change on Main Thread.
How about android system?
I think you are looking for the Choreographer class:
Coordinates the timing of animations, input and drawing. The choreographer receives timing pulses (such as vertical synchronization) from the display subsystem then schedules work to occur as part of rendering the next display frame.

SurfaceView thread - start / stop onDraw calls?

My surfaceView is running in a thread because at times it's animated , however
most the time it just needs to be re-drawn once and left in response to some user interaction , but because its running in the thread onDraw is continually being called... the constant re-draws are slowing it down and making my phone warm :)
I would like to use invalidate(Rect) but can't see how to do this when the thread is controlling onDraw ...
Everything constantly redrawing can't be the way i should go , any help will be greatly appriciated ...
In your thread, you can call wait() after calling onDraw(). This will force the thread to sleep until prompted to continue working. Once the user has interacted and you want to resume animation, call notify() on the thread to wake it up and have it redraw.
If that doesn't exactly solve your problem, consider putting the wait() inside of an if statement so it will only happen after some condition is met.

Opengl-es calling onDrawFrame manually

I am creating a game loop and I need to be able to call onDrawFrame (from inside the renderer manually) in order to "skip frames" if I find that I am falling behind on processes.
Currently I have a GLSurfaceView class that calls
setRenderer(glSurfaceRenderer);
With this set up I understand that onDrawFrame is called every tick.
I tried putting the above call inside a method so that I could call it from inside my game loop but on the second run of the game loop I crash with the message saying
setRenderer has already been called for this instance
Is there a way to call the renderer manually every frame
Will just calling the
onDrawFrame
method work properly. Or is it not good practice to control the renderer in such a way when using openGL
I don't see how calling setRenderer() nor manually calling onDrawFrame() in the game loop will solve anything. You should refactor your rendering calls to take into account the time it takes draw so in other words time based animation. In any case manually calling onDrawFrame() without a call to eglMakeCurrent() before any drawing calls won't work as you have both the renderer and game loop thread drawing.
Edit: Since you are using GLSurfaceView, you can call requestRender() from your game loop to trigger a render if you feel RENDERMODE_CONTINUOUSLY is too slow for you.

ViewFlipper, onClick events not delivered

I have my own implementation of the ViewFlipper (that exactly mocks the Android code, I wrote it before I realized this), the only difference being the fact that I hardcoded an inAnimation and an outAnimation in mine.
One side of the ViewFlipper has a 'flip' button which flips. The other side has a 'save' and 'cancel' button which flips it back. The 'save' performs a DB operation.
When the save or cancel, it flips the card correctly. If I perform the following operation: flip->cancel->flip->cancel..., it works fine. But when I perform: flip->save->flip, the last flip is non-response and logcat shows me that the touch operation was not delivered because of a timeout. The first thing I checked and ensured was that the database operation was not holding off the UI thread, and it was not!
I use the content of the ViewFlipper (using the View.getContent()) to perform DB operations, throw Toasts, build Alert Dialogs and the like. Might this create issues?
I've read a post somewhere saying that there was an issue with the ViewFlipper with animations and onClick() events not being delivered (the discussion ended with no solution). Am I a victim of this?
Try doing the save operation in a thread even though you are sure its not blocking the UI thread.
If that does not work, then set onTouch listener to the save view.

Categories

Resources