I'm developing an app with sdk 11 (Honeycomb). In this app I make use of hardware acceleration (at application level) to make animations smoother and without it, they are unacceptably sluggish. Since my client really wants to have them, I have to find another solution than turning the acceleration off.
The problem itself is that I have an Activity which contains few WebView elements. 3, to be exact - 1 is always shown and 2 others are used for preloading pages, so they are invisible (I mean positioned off the screen, but still "visible"). I use translation animation to "switch" between them. With hardware acceleration on, they render web pages incorrectly - I get big, flickering black boxes over the page. This is of course unacceptable, so I bypassed the problem by turning hardware acceleration off for all WebViews:
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
I've also tried to set this in xml file (android:layerType="software"), but it worked exactly the same way (as it should be). Anyway, both those methods work pretty well - the animations and WebViews are smooth enough and there are no artifacts. The problem arises however once the orientation changes. Even though I make no important distinctions between portrait and landscape mode in my code, it works like this:
Activity starts in portrait mode, change orientation to landscape, back to portrait, and so on. Everything works as expected.
Activity starts in landscape mode. It works fine. Orientation changes to portrait. Artifacts start to show again. Most often whole screen just goes black with webpage showing through once in the blue moon when I scroll/zoom the page. This is exactly the same as if the WebViews used hardware acceleration. Back to landscape - it works fine again.
This had led me to think that the hardware acceleration might be the problem. I was proved myself right by trying to set software acceleration at different levels of view hierarchy to see if this strange behavior stops. I found out that it does indeed stop, and it works without bugs, but only once whole Activity is software accelerated, which is unacceptable to me (my translation animations! [+slow scrolling in webviews]). If only views/viewgroups in the layout xml file are set to be software accelerated, it still bugs. Is there anything about orientation changes which can trigger such behavior? Any solutions, hacks, hints, suggestions, ideas, thoughts, however incomplete, are welcome - I'm out of those.
If you need more info or some code, I will gladly provide it to you.
Thank you for your time!
Related
I do not know what could it be, but does not look like a performance issue (like doing too much work on the background) because there is no message on LogCat saying Slow measurement, Frames skipped or ConstraintLayout issues. The app animations work perfectly. But, unfortunately, all the clickable elements that I added on the xml:
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
are too slow. That slow, that whenever I click, instead of the smooth animation that moves and starts on the exact pixel I click on, it appears an awful shadow and remains like so for a while (~2 sec).
If it is indeed an android performance issue, how to debug it? Also, I do not know where to start and which information I need to add in order to add valuable information to this question but, if needed, please, ask for it and I will try to add as much information as possible.
The only thing I could say in advance is I am using MVVM and coroutines, so there is no performance issues on that matter, but maybe only UI related?
EDIT:
Samsung J2 Prime and Samsung Galaxy Note 3 work good, all animations are good (even though is a small and old device)
Motorola Zoom and Redmi Note 8 Pro are working with laggy animations (animations are meant only the clickable animation (Ripple effect), the ConstraintLayout animations are working smooth.
How to avoid 'blind pixels'? S8's round-cornered screen may affect layout in a significant way. How to know where I can safely draw anything, and where I have to be aware that some part of drawn pixels may never actually display?
I don't want to force non-fullscreen mode. I just want to know where is my "safe rect". How to get that information?
(possibly in a way that can be applied to every phone no matter what company manufactured it, but device-specific solutions are also very welcome)
edit: added picture for everybody still in 2016:
We were having trouble getting media queries to properly target Android tablets when in portrait orientation for an app I am currently developing. I did some testing using http://pieroxy.net/blog/pages/css-media-queries/test-features.html and discovered that Chrome works as expected when that page is loaded into it, but my app's WebView always registers as being in landscape orientation. I tried locking the activity to portrait only, to no effect. I've combed through my WebView code and AndroidManifest.xml looking for something I may have done to cause this behavior, but have come up empty. I would post relevant code, but I've been unable to find it. Google hasn't helped me so far, does anyone know what may likely be causing this issue? Any guidance on where to continue my bug search would be greatly appreciated.
After much hair pulling, I determined this was happening because it was reporting a height of 0px to the media query. Therefore width > height and it determined it must be a landscape orientation. I assumed it was a timing issue and moved a lot of code to onViewStateRestored but this changed nothing. The solution wound up being, of all things, to change the layout_height of my WebView from wrap_content to 0dp in the XML layout. This minor tweak apparently allowed it to determine a correct height at the right point and all media queries now target as expected.
I am working on an Android custom graph view that uses Canvas#drawLines and a paint object that has antialiasing turned on. My view has hardware acceleration turned on. Occasionally when I pinch zoom in/out, some of the lines in my graph will appear disjointed and they sort of taper off into a gradient. If I change to software layer or disable antialiasing, the issue goes away. Is this a bug with drawLines or does someone have an idea of what might be going on?
The first image exhibits the issue, the second image was moved slightly and demonstrates how the graph looks most of the time, with fully joined lines.
(image demonstrates issue)
(image showing how graph should look - still couple minor gaps)
I think this post by Romain Guy answers some of your question: http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html
Essentially, anti-aliasing is not supported by drawLines when hardware acceleration is turned on. Also remember that hardware acceleration won't always be 'better' for your app. If what you are drawing can be accelerated, your app will benefit from it, but for certain operations it might be worse.
I believe that explains why your lines appear disjointed when hardware accelerated. I'm not too sure it explains why it works when you turn anti-aliasing off, though. I'd imagine it would appear disjointed even with anti-aliasing off, but clearly that is not the case!
Try forcing a refresh after the resize gestures.
Have a look at my old Accelerometer Toy app. (Yeah, it REALLY need updating...) If you don't see the problem with that app then I can probably help.
Description:
My OpenGL game runs fine on phones. However, after a couple of seconds of running on a tablet the 3D rendering goes all green. The 2D overlays (gl) are mostly fine.
This might be triggered by rotation, I can't be sure; no access to a tablet.
A user kindly recording it happening, which I have posted online:
http://www.youtube.com/watch?v=DRfDM673TRA
Questions:
Has anyone seen this before, or know of a possible cause/cure?
Also, can anyone confirm this is is still happening? (BB Rally Lite is free).
Other info:
The game is locked into landscape mode so I wouldn't expect it to do anything on rotation.
Update:
This was a bug in my code.
Tablets have a different default orientation,
which was triggering conditional (bugged) code that never got run on a phone.
The green screen was a result of the bug causing the model's matrix to contain nan (or inf, I can't recall).
If you suffer from a green screen I suggest you start by looking at your matrices.