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).
Related
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.
Hello our application works perfect but when our users move the app to background, after a while coming back to app its been crashing.
For example i open the app then change three pages then move the app to background. after open from background 30 minutes its crash because its try to load activity when i resumed
Another applications do this from mainactivity, for example: instagram,twitter vs vs.
another applications not to try load resume activity, they are trying to main activity
how can i start my app from mainactivity when user come back to app from background ?
well, the better way would be to identify the null objects and reassign or repopulate them in the onResume() method so that the user can actually return to what they were doing.
if you can't or it's not an option, then try this code in every activity that you do not want to return to.
override fun onTrimMemory(level: Int) {
this.finishAffinity()
}
this code closes the active activity as soon as the app goes into background so when returned, the app is forced to start from the launcher activity.
Although I am not convinced that this is the best approach. there might be something better.
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
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.
I have a webview and i have next previous buttons to get to the next or previous picture.
What i want to do if possible is : Can i display the first picture but the webview loads (in the background the other pictures(other URLS) so that are available in the cache when a new picture is needed. Thank you
This is possible if you use two Webviews and a ViewFlipper to change between them.
This way while the user looks at one, the other is loading the content. And when flips(you need to implement) it will bring up instantly the loaded image.