1

I am attempting to make an Android app that will be paired with an iPhone app - both of which will use WebViews for 90% of their content. Creating a new WebView on both platforms takes a non-zero amount of time - for the iPhone I've had some success creating a WebView before the user taps anything, then adding it to the navigation stack when they do.

I'm trying to do the same with Android but the 'Activity' concept is holding me back. It appears that my WebView has to be part of an Activity, and I cannot render the view without that Activity being the one currently shown on screen. Is this the case? If so, is there no ability to preload a WebView and then insert it into an Activity?

Alastair
  • 5,894
  • 7
  • 34
  • 61
  • you can pre-load the HTML code and images (or other bigger elements of your page), but the actual `View` itself as declared in the package `android.view.View`, as the name states, it's a View, it must be visualised, meaning it have to be on-screen to be visualised, and for that it must be with an activity. – Budius Nov 04 '14 at 22:56

2 Answers2

1

Try looking at the Service concept more than Activity for running background tasks. Webview can be run in a service and that service can be loaded onCreate()

Little bit of background/ similar questions

http://developer.android.com/guide/components/services.html

Android: Using WebView outside an Activity context (The negative comments on the top answer shouldn't affect your question)

Community
  • 1
  • 1
Seb Andraos
  • 357
  • 3
  • 15
0

Of course. You can add the webview to your layout with the visibility set to View.GONE and make it visible whenever you want.

eduyayo
  • 2,020
  • 2
  • 15
  • 35