I am writing an learning app that consists of many pages included text and pictures as well and some highlighted code (say C++) for learning.
I decided to implement this by html WebView but there is some disadvantages:
1.Sometimes webview gets blank (i don't know why!!) and this makes bad user experience
2.Rendering time for webview is very slow as opposed to native widgets like textview & imageview etc. and some times it takes 1 second to load the contents.
and some advantages as well :
1.Styling is very easy in html using css specially for code highlighting in my case
approach:I saved them in my asset folder and load them with loadurl() method up to webview.
Is there a better way to create book-like app in android ?
How can I reach better performance ? In addition consider styling matters.
Related
I used the android device monitor to check different News Reader UI and I realized that almost all of them are using Native components (ImageView, TextView, FrameLayout) to display their article instead of a WebView. I was wondering what could have motivated such a choice ?
A webService could return the article with a property containing the extracted and formatted html then the webView could be loaded from this plain html String with java webView.loadData("<div></di>", .., ..) right?
Rendering a webview is slower than calling a web service . If you render webview it will load a whole lot component like css, javascript . But If you call web service , you will only get the data you want and then populate other component like textview , image view etc with .
Can we embed our native Android components in between the normal HTML content and then render it on a webview?
For example, in a simple HTML page, if there is a button, I want to replace it with a Native Android Button.
How can we do that?
As far as I know, this is not possible with WebView (unless you split the HTML into multiple parts and render it in multiple WebViews with your button inserted inbetween, which may or may not work in your case).
Depending on the complexity of your HTML, you may want to consider this github project that renders HTML with native Android widgets: https://github.com/kobjects/htmlview
This might seem to you guys as a stupid question, but it comes into my mind so many times:
Why is there an ImageView in Android? We have a WebView, which is capable of displaying images, and so much more stuff. So why would you provide an ImageView as well? Maybe there is some fundamental reason for this, but I just don't see it. Whenever I want to use some media, I try to use a WebView, because this allows me to change the type of media if I wish to do so, and I do not need another Type of View.
So to not make this question to broad, let's bring it down to this:
In which scenario does an ImageView have big advantages over a WebView?
EDIT
And a second question:
If I have some audio, some html-text and some pictures, which are stored locally on my device, would I use one WebView to display them, or would I use one Type of View for each Type of media?
WebView is a much more expensive widget to use, in terms of memory consumption, than is ImageView.
The reason for the memory cost of WebView is the fact that WebView is powered by a fairly complete copy of WebKit. WebKit is an open source Web rendering engine that forms the heart of major Web browsers, such as Chrome and Safari. While the version of WebKit that lives in Android is one optimized for mobile use, it still represents a fairly substantial code base, and rendering complex Web pages takes up a fair amount of RAM (as anyone with lots of browser tabs on their desktop knows all too well).
FACT: The WebView implementation is such that it will consume more memory if used to download & display images. Always. Also, ImageView has special methods / XML tags for cropping, resizing, scaling & manipulating images (which WebView doesn`t).
A person has a image in the gallery. The persom wants to show it inside the app. What will it do?
Go and host it on an online image hosting website and then pass the url to the WebView?
That ain't a cool Idea.. and people and Google understand that.
Basically image view using for showing image from gallery , drawable or url.Webview for handling or showing web content or html kind of thing.
Well ImageView consumes less memory. ImageView can change the image display options.
ImageView can display images from different sources like "Resources, drawables".
WebView mainly for displaying html pages.
I am working on hybrid app and wanted to know the best practices or good way of architecting/structuring the application.
Should one use one webview per activity or should have one single activity with one just webview and change the html pages that are being loaded?
Can one use one webview on multiple activities?
Certain web pages requires loading of heavy resources such as videoview. Due to this I was thinking of using single webview with different activities if its feasible.
You should go with Single Activity with Single Webview. Wherein load the static resources (Html files , js files images etc. )from local location and go to server for dynamic data.
Call for data from server better to use native layer to avoid cross scripting issue. Having said that , Write all the API's in Java and call each api from WebView either using JavaScriptInterface Mechanism or using ShouldOverrideURL method of webview. Recommended is JavaScriptInterface.
To your answer for question : Its always feasible having one webview with multiple activities. but that's not recommended. One Activity is more than enough to take care of loading complete website with different pages in webview.
Is there a faster way to display Jsoup elements onto android apps?
The app I am working on download and parses a page using jsoup, gets a section of the page I want to display, edit some parts of it, then converts that section's element to HTML and displays it onto a webview.
Is there a faster way to do this? I noticed that getting the HTML from the elements takes a long time. Is there a way to directly add the element onto webview or something else without having to acquire its HTML?
Unfortunately, what you're experiencing is a side effect of trying to do (relatively) complex processing on a mobile device. Keep in mind that your app may be installed on low-resource devices and stuff like this screams low ratings.
Having said that, you usually want to do these sort of complex transformations on the server side, and then send the (formatted) data to the device - which you can then render in your WebView, for example. There is no inherent way to make jsoup faster - you're only limited by the resources of your device (as you already found out).