Multiple accounts on separate web windows? (Android)

I'm new to Android development and I have a question about how WebView processes data (in Java).

I am guessing this will fall under the "cookie" category. But I have two different webViews in different tabs of my application. I would like to have one webview (call it webView1

) listed in one website account and the other ( webView2

) in another account of the same website. For example, I would like to log into two separate Gmail accounts in two web windows at the same time.

The problem I am facing is that after logging into an account on webView1

, webView2

follows suit and logs me into that account. The same problem occurs when logging in webView2

, since logging webView1

into this account is also natural.

Is there a way to get around this? I want my two webViews to act completely independently of each other, that's what it boils down to.

Thank!

+2


source to share


1 answer


I can definitely answer your question. I am basically an iOS developer and I am creating an Android app with the exact opposite effect that the WebView cookie does not use. I created my tabbed webviews to mimic the behavior I use on iOS, but my web elements act completely independently of each other. I want them to have the same login information, but since it costs, I have to log into each tab individually, because they don't play well.

Anyway, my problem can definitely help you and I hope you share your information with me to create the cookie sharing effect I'm looking for ...

Here is my layout main.xml:



<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <WebView
            android:id="@+id/web_engine"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:layout_marginTop="-45dp" />
        <WebView
            android:id="@+id/messages"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:layout_marginTop="-45dp" />
        <WebView
            android:id="@+id/myprofile"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:layout_marginTop="-45dp" />
        <WebView
            android: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;

public class TabsActivity extends TabActivity {
WebView webView;

final String DEFAULT_URL = "http://example.com";


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

setContentView(R.layout.main);

    TabHost mTabHost = 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(new MyWebViewClient());

    webView.loadUrl(DEFAULT_URL);

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

    webView.setWebViewClient(new MyWebViewClient());

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

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

    webView.setWebViewClient(new MyWebViewClient());

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


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

    webView.setWebViewClient(new MyWebViewClient());

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

}



public class MyWebViewClient extends WebViewClient {



    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        // TODO Auto-generated method stub

        view.loadUrl(url);

        return true;

    } 


}
}

      

0


source







All Articles