R World
R World

Reputation: 766

Passing WebView from one activity to another

I am doing hybrid application. It has two activities login and home.

On login activity a web view with many java scripts is loaded. Now I want to use same webview in home activity because it takes some time to load all JavaScript’s.

As per android guide lines we cannot pass view from one activity to another.

How to fix this?

Upvotes: 0

Views: 1340

Answers (1)

Ahsan Zaheer
Ahsan Zaheer

Reputation: 676

I'll reference from @rupps's answer here

MutableContextWrapper mMutableContext=new MutableContextWrapper(context);
WebView mWebView=new WebView(mMutableContext);

and when you want to change the parent of this webview, you can change the context of it.

mMutableContext.setBaseContext(newcontext);

I was also looking for a solution, and after a lot of overflowing my stack came to this solution. Thanks @rupps

Upvotes: 1

Related Questions