tags:

views:

32

answers:

1

Hello! I have some problem with passing a WebView from the first activity to the second activity. I have tried putExtra and so on, but it complains that I'm trying to pass a WebView instead of a String.

Intent intent = new Intent().setClass(this, WebView.class);
intent.putExtra("myPassedWebView", mWebView);
startActivity(intent);  

Any ideas?

Thanks in advance!

+1  A: 

Never pass widgets between activities. You will create memory leaks. Please find another solution to whatever problem you are trying to solve.

CommonsWare
Well, the problem itself is that I have my WebView inside a TabLayout, and I want to free my WebView from the TabLayout. Otherwise, my tabs gonna be at the top even if my WebView is open. Therefore I tried to solve it this way.
Julian Assange
@Julian Assange: Get rid of the tabs, then. You need to design your UI such that the `WebView` resides in a single activity.
CommonsWare
Well, the tabs are needed for the rest of the application, and the WebView appears from one of my earlier views from my TabLayout.
Julian Assange
just get the info you need from the webview and make a new one?
schwiz
@Julian Assange: Then leave the `WebView` in the tab. Or, as schwiz suggests, get the URL from the current `WebView`, pass that in the `Intent` extras, and load up the URL again (I think you may wind up with the same cookies -- not sure about that). You cannot have the same `WebView` in multiple activities.
CommonsWare
@CommonsWare: So instead of the new activity, I pass the cookie values into the Extras and then create my webview in the new activity instead of passing it?
Julian Assange
@Julian Assange: I think so. It is a bit difficult to piece together your app from various questions and comments scattered about SO, so I can't be certain that's the right pattern for you, but it sounds plausible.
CommonsWare
@CommonsWare: Thank you once again, and the solution sounds right. :)
Julian Assange