Confused after WebView very slow on large data sets - android

After many days, I almost finished my first app but the WebView ruined it in the end. Search functionality is way too slow with it.
The HTML/CSS page I wanted to display, after search, can sometimes become very big in size like one made with looping and concatenation over 7100 records from DB.
This takes forever for WebView to load.
I thought WebView would be easier option to start with as my data was HTML/CSS.
Now, I am considering to use some other way like TextView with ScrollView etc. I read that this needs my text to have all its apostrophe (') etc escaped.
Can anyone please suggest me what way should I take now. Please keep in mind that my data is going to be big. Like a user can search data(Book) that is about 25MB. So chances are something the user searches may be in all records that would be 25MB data needs to be displayed with smooth scrolling.
What is the best way to from here. I just need WebView to be replaced with some other View.
Thank you
EDIT:
I also have Arabic text along with English text, in case en/decoding should be considered.

You should do the search and pagination on the server, and use something like infinite scrolling on the client. The problem is not the technology that you chose but how you use it. Sending 25 MB worth of data to the client, at once, is never going to go well.
Take a look at this:
infinite scroll in android webview

Related

How to load data from database for viewpager

In simpler terms, I have a viewpager2 which is supposed to display words and their meanings and users can be able to search and go a specific word just like a dictionary application. The problem is that I have a very huge database of a million words and loading it at once that's forever and slows the app down.
What's the best way to implement this?
My idea was to load five words at a time and load another set if the last word is reached but this seems impractical if the user search for another word. Is there a better method?
Before of all load it in another thread, and also try to load by limiting result

Rendering large images in WebView

I'm a newcomer in development of android apps. But, I'm undertaking what feels like a large project and I'm looking for information on whether it will work or not, before I get to far in.
As I've read, when trying to display very large images in android, it is most useful to use the "webview".
So, I took that advice, split my image into 1024 smaller images, and laid them out in an html table (not quite finished yet). Now, I'm noticing as the table gets larger my phone begins to lag upon scrolling.
My question is, is webview trying to render every single picture at once upon loading? If so, is there a way to make webview only render a set of images at one time? Let's say I'm at 14,000X x 24,000Y on the image, can I set webview to render the next 5,000px in each direction only, or is this necessary at all?
I can't seem to find the information I'm looking for, but will continue to search. Otherwise, any and all help is appreciated. Thanks!
i have exactly same problem and i found use full this library:
https://github.com/nostra13/Android-Universal-Image-Loader
you can configure a lot of parameters and using cache..

Android Application - Multiple Pages with Static Content

I am looking to create an app that has about 50 pages of static content. I can give an example of what it would look like, so that it will be easy to understand the questions.
Imagine a Jokes app, with tens or hundreds of pages
The user can see a full list of jokes, which shows the headings in a list view
Selecting a joke subject will take them to the joke page
From there they can go 'Next' or 'Previous'
They should also be able to favorite a joke
Going to the Favorites pages, will list the favorites for them
The joke pages are static. I could add more jokes with an app update but there is no dynamic content. So I am planning to have any server side code that the app can call.
Now the questions:
In Android, can I achieve this with a single activity (for the joke display) and switch the content based on selection?
There are several to store the jokes - sqlite, separate html pages or just strings.xml. Which is better for these use cases?
If there are multiple headings within a single joke (i.e. formatting as bold for them to stand out), I need to store the formatting along with the content. So HTML looks like the option?
This may be out of scope, but I want to capture the content in a standard way so that if I build an iOS app for this, I can just worry about the UI part and use the same content. Again HTML is the option?
Thanks for looking.
Yes you can achieve this with a single activity.
This is really up to you but Android provides support for SQL Databases. You may also consider looking into content providers.
Note: I would not use strings.xml because you can't load new jokes into strings.xml. If you are getting your jokes dynamically from a website, then you really should either load your content into a database and have the app display from the database, or else just load each html page individually. The html page will be easier as you will basically just be making a browser app, but the database will certainly be faster and cleaner.
HTML is certainly an option, though this question seems a little bit vague. It really depends on how you want to get your jokes. If you want to grab them as HTML pages and just display them, then the work is done for you. If you want to parse through them and display them as an android specific app, then it will be more work but you have more control on the app side.
Yes if you want your app to work cross platform you can use HTML to standardize your view across multiple devices.

android how to make a text file viewer?

This is a concept problem.
I see many text file viewer in android market. They are able to open a txt file with thousand of words. The viewer shows the text content in hundred of pages, and allow go back to previous page, go to next page, etc.
My problem is, as the length of word are different. If you want to go to page 50, do you have to start from page 1 and check how many words is needed to fit in page 1 to page 49, then you know the first English word in page 50?
And when you go back one page, you don't know the first word of page 49. Again, how can I find it out efficiently?
Thank you.
If you don't have experience with text viewers, the best approach is webView based application. You can easily add some HTML/CSS to the text and pass it to web view. WebKit will do all the job. For example, hyphenation. Doing it yourself is kinda tricky, specially for multiple languages. WebKit can do it for your.
Speaking about your concept without WebKit - is it important to let user to change font? If yes, you should re-parse document on every changing, I guess. Anyway, the easiest way is to use percentage and show not exact page, but place that is very near. For example, you can find out the size of one page in pro-cents of the document and use it to get needed portions to show.
Good luck in your research!

Is a listview with webview items appropriate for a news app?

I am building an app that scrapes a certain web site and presents the latest news in a listview, html formattted with an image, a title and a summary. When the user clicks on a row, the news article is showed. It works a bit like the CNet app and similar news apps.
I have no problems with the scraping part, but I am in doubt on how to manage the summary list.
My initial idea is to have a listview where each item is a webview. The listview is populated by a custom ArrayAdapter filled with the scraped html content. Each screen will show the summaries from the 30 most recent articles, ie. up to a month old.
Is this approach recommended or will 30 webviews take up too many system resources?
Would it actually be better to use on big webview, using simple html (ul) to show the summary list?
Also, is an array adaptor the right way to go, or would a cursor be better?
If there are completely different ways to do this, please let me know!
Thanks.
Webview is not a bad approach, but there are better ways. I'd suggest to show the text normally (I mean, in a TextView). I'd use WebView if you are going to show long HTML content that has a complex format or use CSS... but, what you want is showing a preview, so keep it simple. It will be also faster, and more maintainable if you do it in a TextView.
With regards to the adapter... it really depends on how are you persisting the data. If you are just fetching those feeds from internet, parsing them and showing them right away, then you have no choice but using an ArrayAdapter or something like that. On the other hand, if you are persisting your data into a Sqlite database, then CursorAdapter is much better.
Romain Guy, the developer on the Android team who is most vocal on the web helping developers actually said in one of his talks (which you can find on YouTube...not sure which one) that technically you "could" do that, but he'd be extremely upset with you if you did. lol
There is probably too much going on in a WebView to make this the ideal choice of ListView items. I would create a "model" object representing the data for each item that you're abstracting and just make an xml layout that you can populate in a custom adapter.
This video is GREAT info if you're working with ListView
http://www.youtube.com/watch?v=wDBM6wVEO70
I don't see why the application wouldn't be able to handle the 30 html feeds, so you should be good there.
A ListView should be fine to use. Obviously, this all depends on how you want the UI to look and feel.
Lastly, a cursor adapter is used when using a cursor from a db query. Unless you're storing the feeds in a local db, this doesn't seem to be what you're doing. So, the array adapter should work fine for you.

Categories

Resources