Activity with webView Loading every time - java

In my app i have button when it clicked the app goes to another activity with webView to show HTML table
The issue here is when i press back and return to the same activity the webView load agin and it take while how can i prevent it from loading over and over agin and will turnning the HTML table to listview will make it loade faster if yes . How ?

You can Preserving the state of an Android WebView on screen orientation change or activity is paused.
If you’ve tried to use a WebView inside your app, you know that the standard behavior on screen orientation change is not satisfactory in most cases because the full state of the WebView is not preserved or similarly when your activity is pause same situation WebView will change their sate.
possible implementation to keep the full state of the WebView
here complete tutorial and code is given you can get idea from this code&tutorial

Related

How to Show Custom View (FAB) On All Screen in Android

I want to show my custom floating button on all screen in my app without putting it in each activity.
Do we have some Global Activity like put a code once will show the Custom View all screen and hide/remove when app killed
I tried lot of things like Screen Overlay display over all apps
Please check code here - How to display custom view on all screen in android from my library
I've never tried to do it the Java/Kotlin way. But have you considered using Fragments?
You can declare xml layout and code for one Activity with a FrameLayout container and an FAB. The container holds all your screens and they switch between each other in the container. The FAB is on top and therefore will be displayed no matter the screen.
The Activity has a reference to any screen that might be displayed in it, so the FAB can behave accordingly.
Not sure if this helps. Perhaps if I see some pictures, I could suggest better.
Related Read:
Creating a fragment: here
Fragment Transactions: here

Is it possible to prevent WebView or any View from being destroyed?

So my understanding is that View has different lifecycle then Fragment, I have noticed that by adding confingChanges to MainActivity android:name=".MainActivity" android:configChanges="orientation|screenSize|keyboardHidden", my WebView (or maybe the whole Fragment) is not being destroyed on rotation (or at least it seems like it is not being destroyed) i.e the Website is not being reloaded, so how does android does this? Is there any way to save the WebView when the fragment is being destroyed and then pass this webView to the fragment when it is being created?
I thought maybe following would work: detach the view in the onPause or any other method down the line (Fragments Lifecycle) save the View somewhere and then pass it back in the onCreateView method?
Background to the App: there is bottom navigation Bar which has 4 elements when one of these elements is clicked a new fragment is created and displayed inside of the main activity, while the Fragment before is being destroyed (this is achived using getSupportFragmentMenager().beginTransaction().replace().commit();), one of these Fragments has WebView in it, i would like to prevent the WebView from being destroyed?
I have achived the following: I am saving the state of the WebView inside onPause method and inside onSavedInstace method (for the cases when the activity itself gets destroyed), but the problem with this is that the Input that the user puts inside forms during the session but not sending them gets lost on reload/restore of the WebView, so would like to save the Webview so that even this remains when the user comes back to the site.

Android: open hidden webview activity or fragment

I'm developing an android app which shows a listview.
When the user clicks on an Item on the list, i need the app opens a regular activity with some details and, in background or in "hidden mode", opens a webview which load a URL (of my blog).
I need it because i want to trace which items are opened, analyzing the Google Analytics information on my blog; in this way, everytime someone clicks on an Item, i'll find the information on my blog.
Is there any way to do it?
The correct way to open a hidden webview is to call webView.setVisibility(View.GONE) on the OnCreate method

Load data to WebView in background without open Activity

I need load in background html-page in WebView in Activity. Only real background without open Activity.
I try use moveTaskToBack( true); in onCreate. But this is does not always correct, Activity sometimes opens.
What is best way load data to WebView in background?
p.s. my real task: load data from URL in background with javascript-injections (in my Widget).

Preloading the Webview in Activity A and Passing it to Activity B for faster loading

in one of my app i am using webview to load the pages, the scenario is i have Activity A and Activity B, Activity A displays the menu list, on selection of any of the item in the list it will open Activity B, in Activity B I am doing all the webview related activities like loading webview using the URL but its taking lot of time to display that page, my question here is there anyway i can preload the webview in activity A and pass it to B for immediate loading.
if it's possible to preload the webview in Activity A and pass it to Activity B for immediate rendering please let me know how it is doable?
Note : I can use progress dialog in Activity A until the webview loads(wait till onPageFinished) get called and start the Activity B, but how can i make the webview load immediately here?
You cant share of transfer views between activities in any way. So you should stay within single activity (you can use fragments to organize your views). Create webview, hide it, start loading data. Show webview when data is loaded.
P.S. You can manually download html source code and/or some resources to use with webview later... but this can be tricky.
You cannot share views between activities, but depending on what kind of page you're loading from the url, you could cache the html into a file on sd card, then load WebView in activity B from this file.

Categories