Question

I have various pieces of generated HTML/JS that I load into Activity with WebView#loadDataWithBaseURL. Is there a way to not load in again and again during Activity lifecycle? For example - user goes to check the message and then calls the app again. At that point - the Activity is stopped and probably destroyed, when it's loaded again I do not want to hiccup on loading the content user was already viewing.

Was it helpful?

Solution

For example - user goes to check the message and then calls the app again. At that point - the Activity is stopped and probably destroyed

If the user directly visited the Notification, or clicked HOME, your activity is stopped but not destroyed. In these cases, your WebView should not change content unless you change it.

Your activity will be destroyed if the user presses BACK, or Android needs to close you out because of memory constraints.

In the BACK case, the user is expressly telling you to go away, so reloading your data seems reasonable.

In the memory-constraint way, by definition the device is short on memory, so you're going to need to reload the data if and when you are brought back to the foreground.

OTHER TIPS

When i click HOME, and later i restart my app, the content of WebView retained. But when i trigger a Intent(such as barcode scanner), after the Intent finished and come back to my app, the WebView in my app was reloaded.

Could i keep my WebView content when the Intent returned?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top