Skip to content Skip to sidebar Skip to footer

Multiple Log-ins On Separate Webviews? (android)

I'm fairly new to Android development, and I have a question about how WebViews handle data (in Java). I'm assuming this would fall under the 'cookie' category. But what I have is

Solution 1:

I can definitely answer your question. I am mainly an iOS developer and I am creating an Android app with the exact opposite effect of webView cookies not sharing. I created my webviews in tabs to simulate the behavior I use in iOS, but my webViews are acting completely independant of one another. I want them to share the same login info, but as it stands I must login to each tab individually because they aren't playing nice.

Either way, my problem can definitely help you and I would hope that you share your info with me to create the cookie sharing effect I am searching for...

Here is my main.xml layout:

<?xml version="1.0" encoding="utf-8"?><TabHostxmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/tabhost"android:layout_width="fill_parent"android:layout_height="fill_parent"><LinearLayoutandroid:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TabWidgetandroid:id="@android:id/tabs"android:layout_width="fill_parent"android:layout_height="wrap_content" /><FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="fill_parent"android:layout_height="fill_parent"><WebViewandroid:id="@+id/web_engine"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_gravity="bottom"android:layout_marginTop="-45dp" /><WebViewandroid:id="@+id/messages"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_gravity="bottom"android:layout_marginTop="-45dp" /><WebViewandroid:id="@+id/myprofile"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_gravity="bottom"android:layout_marginTop="-45dp" /><WebViewandroid:id="@+id/rncorner"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_gravity="bottom"android:layout_marginTop="-45dp" /></FrameLayout></LinearLayout></TabHost>

Here is my Activity:

package com.example.tabs;


import android.app.TabActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;

publicclassTabsActivityextendsTabActivity {
WebView webView;

finalStringDEFAULT_URL="http://example.com";


/** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

    TabHostmTabHost= getTabHost();

    mTabHost.addTab(mTabHost.newTabSpec("Home").setIndicator("Home",getResources().getDrawable(R.drawable.home)).setContent(R.id.web_engine));
    mTabHost.addTab(mTabHost.newTabSpec("Messages").setIndicator("Messages",getResources().getDrawable(R.drawable.messages)).setContent(R.id.messages));
    mTabHost.addTab(mTabHost.newTabSpec("My Profile").setIndicator("My Profile", getResources().getDrawable(R.drawable.myprofile)).setContent(R.id.myprofile));
    mTabHost.addTab(mTabHost.newTabSpec("Map").setIndicator("Map", getResources().getDrawable(R.drawable.rncorner)).setContent(R.id.rncorner));

    mTabHost.setCurrentTab(0);

    //home
    webView = (WebView)findViewById(R.id.web_engine);

    webView.setWebViewClient(newMyWebViewClient());

    webView.loadUrl(DEFAULT_URL);

    //messages
    webView = (WebView)findViewById(R.id.messages);

    webView.setWebViewClient(newMyWebViewClient());

    webView.loadUrl("http://example.com/index.php2");

    //my profile
    webView = (WebView)findViewById(R.id.myprofile);

    webView.setWebViewClient(newMyWebViewClient());

    webView.loadUrl("http://example.com/index.php3");


    //rncorner
    webView = (WebView)findViewById(R.id.rncorner);

    webView.setWebViewClient(newMyWebViewClient());

    webView.loadUrl("http://example.com/index.php4");

}



publicclassMyWebViewClientextendsWebViewClient {



    @OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {

        // TODO Auto-generated method stub

        view.loadUrl(url);

        returntrue;

    } 


}
}

Post a Comment for "Multiple Log-ins On Separate Webviews? (android)"