Prevent Android Webview to show blank screen while navigating - java

I created an Android WebView app. Right now, I am facing 1-2 seconds of blank screen when navigate between pages. I cache all the resource (js, css, html), but it still show me the blank screen for few hundred milliseconds. It is very quick, but the blank screen still noticeable.
Is there any way to skip or hold the transition screen? Like prevent the page to refresh until all DOM and resources are fully loaded.

Make it into a single-page app!
Control the transitions yourself with AJAX (or an framework that abstracts it).
This way you can load the site content and only update it when it is done loading (or add your own loader animation)

Related

Android WebView: Display only half of a webpage

Currently I have a HTML page with a container containing element A on the left side and element B on the right side. I'm trying to view this page using ViewPager with two tabs ie. have only half of the webpage displayed on Tab1 and the other half on Tab2. This makes it so that even if the user chooses to scroll all the way on Tab1, he can never see the content on the right side unless he swipes to Tab2. The size can be determined by 0-50% and 51% - 100% horizontally if possible.
Any idea how this can be implemented?
Android webview is a kind of browser, it will behave the same as another bowser is doing for showing webpage, as per your requirement ask your Web development team to make it browser compatible, and check their output in Chrome, Firefox browser in your device then integrate into Android Webview.

Android autolink links always start browser

I'm working on an Android application with an activity dedicated to a webview. I also have a chat section of the app that autolinks web links in the messages. I've created a onItemClick listener on the chat messages to start the webview activity. This listener works when I click the whole chat bubble, but I noticed that if I only click the highlighted link in the message, the listener isn't called and instead my default browser is loaded up.
I put a log message in front of every instance of an intent with ACTION_VIEW, thinking that some other part of my app may be launching the browser, but it doesn't seem like this is the case.
I'm wondering if android has any default methods that catch autolink urls and starts the browser that I could override. Otherwise, I was thinking that I could turn off autolink and imitate the appearance of links with the blue text and the underline, but this seems like a poor solution.
Thanks ahead for any tips on how Android works!
I encountered this situation too, where I have autolink set up in TextViews to automatically handle URLs in TextViews. However, the default behavior is to open the web page in an external browser, so how do we make it open in a webview activity (for example)?
Beneath the hood, this is handled for TextView by LinkMovementMethod. However, the behavior is difficult to customize. There is a 3rd party enhancement over LinkMovementMethod, known as BetterLinkMovementMethod, described in more detail in this blog post. With just a few lines of code changes, the TextView autolinks can be made to open in your webview activity (and clearly, all kinds of other behaviors can be customized as desired).

GWT load fragments after application start

I am creating an app in GWT, and I just recently implemented code splitting there. I reduced the application size from 1.1MB to 570kB which is nice, so the startup time of the application is now faster (we are using special server where 500kB really matters... not important for my question though ...). After the application starts (in other words user can see login page, can login and use basic parts of the app), I would like to download the rest of the fragments.
I know the fragment will be downloaded when the code in the fragment is needed. But one of the fragments is about 300kB. So when I click in the menu of my app on an item, that causes this fragment to be downloaded, there is a very noticeable delay (1 - 2s), before the user gets a response.
Now I understand that this will most likely happen only once and then the fragment will be cached for like a year, so it will load faster next time. But for example when I try it again on another device, I will have to download fragment for the first time again.
I just need to be sure, that when user launches my app on a phone/tablet using wifi, then disconnects from the wifi or gets out of its range, he will still be able to launch the code in the fragments, even if he didn't launch the things that cause downloading them while he was still connected to the server.
Now he would have to open 3 menu items, to download all the fragments which is annoying.
So in short:
I want my initial download to stay 570kB, and download the rest of the app as soon as possible on the background (if possible).
EDIT:
I found http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html#sequence where you can setup initial loading sequence, so I guess it is what I am looking for. Not sure though if they are loaded asynchronously, because the login screen appears after the fragments are downloaded.
You can cause all fragments to be downloaded after the login panel is rendered. Simply call some method inside the rest of the code - it does not need to do something visible.
Also, if you plan to load all code this way, you only need to split one fragment - your entry point with the login panel. Each split point (a) slightly increases the overall size of the application, and (b) increases, sometimes significantly, the size of the leftover fragment which still needs to be loaded for the first fragment to show up. Thus, there is no point in having more than the initial fragment and the rest of the app, given your requirements.

Texture loading: Everything at once OR un-/loading the needed assets?

We've been developing quite a huge game for android on the basis of AndEngine. So we have a lot of assets to load, especially textures.
At the moment everything (sound, textures etc) for every screen (menu, shop, etc etc) is loaded when the app starts (while showing a progress bar). This way the user only has to wait once about 16 seconds at the start of the game. We think that this is a pretty pleasant solution from the users perspective but might it be bad in terms of battery usage / memory usage or any other reasons?
What arguments speak for a solution where we unload all the screen specific assets of the active screen and load the assets needed for the next screen?
In my opinion, the best way to go is "lazy loading", i.e., load resources only when you need them. That way you are not making the user wait for resources he will not use. So what I do is, when the app starts, I load the menu's resources during an opening splash screen, and when the user go to the play scene (for example), I unload the menu resources (hence clearing memory), and load the relevant resources for the game sequence, during yet another, different loading splash screen. That way, in total, the user waits the minimum time, and the memory is loaded with needed resources only.
Besides, from a user's point of view, I think it can be annoying to wait for a whole app to load, when all you want is to show your friend the score you reached.
I've done an app that uses a lot of textures (both HD and LOW depending of the device, etc) and I use the "lazy loading" approach. This app is meant for the kids so there's a lot of animations and illustrations. My first menu is so complex that I have to load 19 textures (2044x2044) so I need to show a splash with a progress bar. From that menu you can choose to play some mini-games or watch some videos. If the kid choose to play a game I show another progress bar while the game textures are loading (another 5/6 2044x2044 textures depending on the mini game). If the kid comes back do the main menu I unload the game textures. If the kid wants to watch some movies, well in this case "it gets worse" because now I have to switch to "Android Activities" instead of AndEngine, so I unload the Main menu textures otherwise OutOfMemory would be thrown. If the kid comes back to the main menu all the textures will be loaded again. I think this is the best approach for you, "lazy loading", and you'll find out that this approach will save you a lot of memory.

Java Applets vs Back Button

I noticed that if you're playing a song at http://listen.grooveshark.com/ and you hit the back button Flash is smart enough to keep on playing the music while navigating "back" inside the Flash application.
Is it possible to implement this sort of thing using Java Applets, or do Applets alway shut down when you navigate away from the page (even though the resulting page contains the same applet)?
Looks like grooveshark is being tricky with the URL fragment. They store the search after the # fragment delimiter in the URL, e.g. do a search for ween, and you get this URL
http://listen.grooveshark.com/#/search/songs/?query=ween
Then do a search for bungle and the URL changes to
http://listen.grooveshark.com/#/search/songs/?query=bungle
If you click the back button in your browser, the URL changes to the previous "ween" one, but the browser remains on the same page, because everything before the fragment identifier is the same. There's some javascript that's detecting the changed fragment and updating the UI accordingly.
You could probably do something like this with an applet, but it seems better suited to javascript. The good news is, your applet is going to be cached by the browser, so if you do switch to a different page the applet loading will happen quickly.
http://java.sun.com/docs/books/tutorial/deployment/applet/lifeCycle.html
When the user leaves the page, for
example, to go to another page, the
browser stops and destroys the applet.
The state of the applet is not
preserved. When the user returns to
the page, the browser intializes and
starts a new instance of the applet.
That being said, what you could do is save the state to the server when the applet is stopped and then restore the state from the server when it starts again. If you make it a signed applet it should be able to save the state locally.

Categories

Resources