Saving webview state when switching tabs...

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Saving webview state when switching tabs...

Postby brybam » Fri Jul 09, 2010 10:00 pm

RIght now i'm using Tabhost with two tabs that have webviews inside them. Each tab has a different activity with the webview inside it.

when i switch back and fourth between the two tabs it reloads the webview. How can i make it preserve the webview's state and not require it to be reloaded?
brybam
Developer
Developer
 
Posts: 27
Joined: Fri May 21, 2010 1:03 am

Top

Re: Saving webview state when switching tabs...

Postby brybam » Sat Jul 10, 2010 2:46 am

does anyone at least know if this can be done?
brybam
Developer
Developer
 
Posts: 27
Joined: Fri May 21, 2010 1:03 am

Re: Saving webview state when switching tabs...

Postby ranjandeo » Sat Jul 10, 2010 5:41 am

Hi brybam,

Webview doesn't change its stae while switching between tabhosts.
You should check something else that might be generating such situation.

Have u taken same webview in both tabhosts?
Ranjan Deo
User avatar
ranjandeo
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon May 31, 2010 6:20 am
Location: Kolkata, India

Re: Saving webview state when switching tabs...

Postby brybam » Sat Jul 10, 2010 6:36 am

each tab has it's own activity with it's own webview. and every time i switch back and fourth between the tabs i have to wait for it to load the URL. It doesn't stay loaded :/
brybam
Developer
Developer
 
Posts: 27
Joined: Fri May 21, 2010 1:03 am

Re: Saving webview state when switching tabs...

Postby ranjandeo » Sat Jul 10, 2010 6:41 am

You should check out some other part of your code.
I have worked with this, it doesn't change its state while switching between tabs.
If it is being happened then it is strange!!!
Can you please post your code or you can mail me this at ranjandeo@gmail.com
I think now if I will have the code only then I can say something in your case.
Thank You :-)
Ranjan Deo
User avatar
ranjandeo
Experienced Developer
Experienced Developer
 
Posts: 84
Joined: Mon May 31, 2010 6:20 am
Location: Kolkata, India

Re: Saving webview state when switching tabs...

Postby brybam » Sat Jul 10, 2010 7:16 am

I have two activities that are identical. here's one thats inside the first tab and it reload evertime i switch back to it from another tab. It doesn't appear to be already loaded. If you need to take a look at the code for the tab class just lemme kno. thanks for looking at this!

The only thing out of the ordinary is i use the cookie sync manager, cuz for my app it need the website i have in the webview (i just changed it for this example) i need it to keep the user logged in. and that seems to do the trick.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.my.package;
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7. import android.content.Intent;
  8. import android.os.Bundle;
  9. import android.view.KeyEvent;
  10. import android.view.Menu;
  11. import android.view.MenuInflater;
  12. import android.view.MenuItem;
  13. import android.view.Window;
  14. import android.webkit.CookieSyncManager;
  15. import android.webkit.WebChromeClient;
  16. import android.webkit.WebView;
  17. import android.webkit.WebViewClient;
  18. public class Fbook extends Activity {
  19.        
  20.                 /** Called when the activity is first created. */
  21.         WebView webview;
  22.         @Override
  23.        
  24.        
  25.     public void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.        
  28.         setContentView(R.layout.main);
  29.         CookieSyncManager.createInstance(this);
  30.         CookieSyncManager.getInstance().startSync();
  31.         webview = (WebView) findViewById(R.id.webview);
  32.         webview.setWebViewClient(new googleClient());
  33.         webview.getSettings().setJavaScriptEnabled(true);
  34.         webview.getSettings().setPluginsEnabled(true);
  35.         webview.loadUrl("http://google.com");
  36.         CookieSyncManager.getInstance().sync();
  37.        
  38.     }
  39.         private class googleClient extends WebViewClient {
  40.             @Override
  41.             public boolean shouldOverrideUrlLoading(WebView view, String url)
  42. {                      
  43.                 view.loadUrl(url);
  44.                 return true;
  45.             }
  46.         }
  47.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  48.             if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
  49.                 webview.goBack();
  50.                 return true;
  51.             }
  52.                 if (keyCode == KeyEvent.KEYCODE_SEARCH) {
  53.                
  54.                    webview.loadUrl("http://www.bing.com");
  55.  
  56.                   }  
  57.             return super.onKeyDown(keyCode, event);  
  58.             }
  59.            
  60.        
  61.        
  62.        
  63.                 public boolean onCreateOptionsMenu (Menu menu) {
  64.                         super.onCreateOptionsMenu(menu);
  65.                         MenuInflater inflater = getMenuInflater();
  66.                         inflater.inflate(R.menu.menu, menu);
  67.                         return true;
  68.                 }
  69.                
  70.         @Override
  71.         public boolean onOptionsItemSelected (MenuItem item) {
  72.                         switch (item.getItemId()) {
  73.                         case R.id.toggle:
  74.                                 Intent k = new Intent(this, Other.class);
  75.                                 startActivity(k);
  76.                                 return true;
  77.                        
  78.                         case R.id.refresh:
  79.                                 webview.reload();
  80.                                 return true;
  81.                
  82.        
  83.         }
  84.         return false;
  85.         }
  86.        
  87.        
  88. }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4
brybam
Developer
Developer
 
Posts: 27
Joined: Fri May 21, 2010 1:03 am

Top

Re: Saving webview state when switching tabs...

Postby brybam » Mon Jul 12, 2010 4:21 am

any ideas?
brybam
Developer
Developer
 
Posts: 27
Joined: Fri May 21, 2010 1:03 am

Re: Saving webview state when switching tabs...

Postby brybam » Mon Jul 12, 2010 9:46 am

I figured it out. I just didnt have anything in the tabspec
brybam
Developer
Developer
 
Posts: 27
Joined: Fri May 21, 2010 1:03 am

Re: Saving webview state when switching tabs...

Postby ujjwal.wadhawan » Wed Nov 03, 2010 4:19 pm

@brybam.

I am in a similar state. Can you pls share your Tab code for reference
ujjwal.wadhawan
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Nov 03, 2010 4:17 pm

Top

Return to General

Who is online

Users browsing this forum: No registered users and 3 guests