Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid tabs - avoid recreating activities on tab clicks
    primarykey
    data
    text
    <p>I've put a little app together that has three tabs to show three different web pages. It does work however I am bit worried I haven't got enough control over how this whole thing works. When I click a tab, I get a web page loaded (see code sample below), now when I click another tab another page loads in another view. When I go back to the first tab, the whole thing get initilized again and the page loads. Is there a way how I can control this and keep the underneeth tab's activity in its current state as long as I want (and say only "refresh" the page when it changes).</p> <p>do I need to handle onPause()/onResume() methods for that or instead implement my tabs as views of a single activity (is this possible at all?)? How do I store the state of my activity to avoid re-initializing it every time?</p> <p>this how activities are hooked to tabs:</p> <pre><code>intent = new Intent().setClass(this, tab_schedule.class); spec = tabHost.newTabSpec("Schedule").setIndicator("Schedule", res.getDrawable(R.drawable.tab_icon_schedule)).setContent( intent); tabHost.addTab(spec); </code></pre> <p>the tab_schedule.class does a simple web page load:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab_people); try { WebView currentView = (WebView) findViewById(R.id.tab_people_WebView); currentView.getSettings().setJavaScriptEnabled(true); currentView.loadUrl("http://pda.lenta.ru"); } catch (Exception e) { Log.v("webClientInit", e.getMessage()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload