I have a problem with my videogame in Android. It shuts down randomly without saying anything while I'm playing it for a while. Before, It didn't close but now somehow, is doing it.
After this, I optimized the code and got a great memory improvement but it keeps doing the same at the same frecuency, which makes me think that maybe is not a memory leak.
It is not an unhandled expcetion neither, because I have a try/catch capturing all the exceptions in my game loop.
So I was wondering what could trigger a force close in my Android videogame... what would you suggest?
Maybe is because the device becomes very hot.
Is it possible that in a long loop could decide to shut down because it is taking so long and without saying anything?
Those two are my main hipotesis right now. I don't have any clue what is going on.
Related
I just try to understand the reason of it. Our app is really stable and optimized, but time to time it just switch off during the work on foreground mode. User is using it, and it' just closed without any crash or ANR messages - really bad experience. What we already did:
use UncaughtExceptionHandler and print logs to the disk for analyzing. Logs are empty, not information about crashes for these cases
used Firebase crashlityc - is empty too
checked app with help profiler and leakcanary - no leak, memory using ~200 Mb
A bit words about our app:
clear arhitecture, Kotlin, MVVM, coroutines, dagger, retrofit, room, one single activity app
app should work all time, infinitely. App is an interface for hardware terminal.
the most part of fragments are stored into the backstack and reused again, it help to make screen opening faster after first fragment using. No leak with it, no fragment or viewModels duplicates
we use glide for downloading and previewing user avatars. I'm afraid, that leaks could be a part of bitmaps or jpg. Profiler doesn't show it after 1-2 hours tests, but I didn't test it during for ex. one week
possible app interruptions happen more often, when device is uncharged or just started (first 10-20 minutes after device start)
the most part of clients has a bad WIFI connections
we have ~10 modules, the most part of them are own canvas libs
crashes happen in random moments...
we also have ANR problem for some clients, but we added ANR watchdog, so soon we will know the reason of it.
we have 50-60 singletons. I'm not sure, that is bad or good. The first plan was using much memory to make app faster.
For me it looks like a native crash or system kill, but how to repeat it? I still don't understand the real reason of it. If you faced with similar problem, please describe your experience, it could be helpful for us. Thx!
After playing my libgdx-game for some time, it just freezes. the game loop is not being executed anymore and it does not react to any input; the game can just be killed.
Logcat says this:
The memory graph shows:
(The freeze starts at about 8m30s. Before this time the game is running normally.)
The question: What is happing here? What do I have to do to avoid this game crash?
Could you post more logcat? It's hard do gather any information as to what is causing the problem just by looking at it saying it's suspending all threads.
This usually happens when you run out of memory. Do you have peices of code which load stuff into memory? You may want to take a look at that. Just a possibility, but maybe you are running out of memory. I know what the memory graph shows, but I had a similar problem and I fixed it by optimizing some asset loading.
(you may want to use asset manager to handle memory optimization)
https://github.com/libgdx/libgdx/wiki/Managing-your-assets
If that is not the case, please post some code. (or more logcat)
My app is hanging when returning from one activity back to a ListView activity. I know the ListView is slow and RecyclerView is a better replacement, however I don't think this would be causing complete UI freezing for multiple seconds (I see ListView lag however this hang is 100% unresponsiveness). The hanging is almost always persistent until you close and re-open the app, and ANR is almost always triggered.
I have messed around with TraceView and see a lot of Object.wait() calls taking up CPU time, but I don't know how to interpret that. Where can I go from here?
Edit (more info):
There is a lot going on from SQLite, image loading, rest calls and so on going on in the app and I've been running Strict Mode and fixing issues but nothing shows up in Strict Mode logs when this type of hang happens (which is very reproduceable)
Screenshot of systrace during hang
So I am making an android game, and so far it's working fairly well. I was using System.exit(0) to kill it, but I know that is an improper way to do it. So I used finish() instead, which does close the program. The problem is, that when I reopen it, the screen is blank. It seems that for some reason, the glSurfaceView isn't being released, and continues to run, and that upon reopening the game, it loses focus of it? The sounds and everything play, and my Logcats display information, so the game is in fact running, but just not the screen. Now before people start jumping on the (just let android take care of closing your app bandwagon) I have my reasons for doing so. For one, telling me that android is efficient enough to do this is a lie, otherwise we would not have the need to restart the devices every other day. Nothing more bothersome that a lag driven phone that can barely even handle an incoming call because it has so much shit on it running. So yea, I would like to be able to close the app.
So yea, how does one correctly to the glSurfaceView that it is time to close itself down? or to tell the Activities class that it needs to release it's handle to the glSurfaceView since closing the app sure doesn't do that.
Hi I'm getting ANR (Application Not Responding) errors but I can't understand why. If I click "Wait" everything works perfectly and the ANR doesn't come back anymore.
Now, I do know that when using MediaPlayer as a service is good practice using .prepareAsync and the onPrepared() method rather than simple .prepare() and .start(). It doesn't lock the UI thread and works great.
The problem is that all my ANRs are not happening when opening files (you would guess higher processor there), but randomly when they are playing and when the cpu is at few % at most. As I mentioned earlier NOTHING is remotely close to being unresponsive and there is little left on the UI thread.
The only clue is that I don't get ANRs the first time I play a track, but only after it has been changed. I thought that the prepareAsync threads were colliding and I added a lock myself. no change.
I tried to release the media player each time before starting a new track. no change
I tried to reset, stop etc in many sequences. no change.
Has anybody experienced the same thing?
As a workaround, is there any way to automatically dismiss the ANR? I know it's not the answer but I can't find any options. I am on a rooted tablet (I compiled the ROM) and it is only for myself - no distribution
thanks
A standard Service actually runs on the main Thread, if you are seeing ANRs perhaps you should move the entire MediaPlayer to another Thread. To quote the documentation
Most confusion about the Service class actually revolves around what it is not:
A Service is not a separate process.
A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).
You are already using prepareAsync(), but as you stated the error occurs while the MediaPlayer is running, not preparing. Without more detail on what exactly causes the ANR, I believe switching to a HandlerThread is your best option.