我对 Android 开发相当陌生,我有一个关于 WebViews 如何处理数据(在 Java 中)的问题。
我假设这属于“cookie”类别。但我在应用程序的不同选项卡上有两个不同的 webView。我想要一个 webView(称之为webView1
) 登录网站的一个帐户,而另一个 (webView2
)登录同一网站的另一个帐户。例如,我想同时登录两个 webView 中的两个单独的 Gmail 帐户。
我遇到的问题是,一旦我登录帐户webView1
, webView2
我也跟着做,然后将我登录到该帐户。当我登录时出现同样的问题webView2
, as webView1
自然也登录到该帐户。
有什么办法可以解决这个问题吗?我希望我的两个 webView 能够完全独立地运行,这就是最终的结果。
Thanks!
我绝对可以回答你的问题。我主要是一名 iOS 开发人员,我正在创建一个 Android 应用程序,其效果与 webView cookie 不共享完全相反。我在选项卡中创建了 Web 视图来模拟我在 iOS 中使用的行为,但我的 Web 视图的行为完全相互独立。我希望他们共享相同的登录信息,但就目前情况而言,我必须单独登录每个选项卡,因为它们玩得不好。
不管怎样,我的问题绝对可以帮助你,我希望你与我分享你的信息来创建我正在寻找的cookie共享效果......
这是我的 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>
这是我的活动:
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;
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)