关于多开Webview的问题

一个Activity承载一个WebView,通过startActivity 来实现多开页面。代码如下

package com.lingdong.service.buyer.activity;  

import android.content.Intent;  
import android.content.res.Configuration;  
import android.os.Bundle;  
import android.view.KeyEvent;  
import android.view.Menu;  
import android.view.View;  
import android.widget.FrameLayout;  

import com.lingdong.core.EmptyUtils;  
import com.lingdong.core.base.activity.LBaseActivity;  
import com.lingdong.service.buyer.R;  
import com.lingdong.service.buyer.ShopConfigure;  

import io.dcloud.EntryProxy;  
import io.dcloud.common.DHInterface.ISysEventListener.SysEventType;  
import io.dcloud.common.DHInterface.IWebview;  
import io.dcloud.common.DHInterface.IWebviewStateListener;  
import io.dcloud.feature.internal.sdk.SDK;  

/**  
 * 本demo为以webview控件方式集成5+ sdk,  
 */  
public class ShopWebViewActivity extends LBaseActivity {  

    String extras = "";  
    String title, pageUrl;  
    EntryProxy mEntryProxy = null;  
    IWebview webview = null;  
    FrameLayout activity_shop_h5_web_fl_content;  
    private Bundle mBundle;  

    @Override  
    public int getLayoutRes() {  
        return R.layout.activity_shop_h5_web;  
    }  

    @Override  
    protected void initView() {  
        super.initView();  
        if (mEntryProxy == null) {  
            activity_shop_h5_web_fl_content = (FrameLayout) findViewById(R.id.activity_shop_h5_web_fl_content);  
            // 初始化5+内核  
            mEntryProxy = EntryProxy.init(this, ShopMainActivity.I_CORE_STATUS_LISTENER);  
            // 启动5+内核  
            mEntryProxy.onCreate(this, mBundle, SDK.IntegratedMode.WEBVIEW, null);  
        }  
        activity_shop_h5_web_fl_content.getViewTreeObserver()  
                .addOnGlobalLayoutListener(() -> webview.onRootViewGlobalLayout(activity_shop_h5_web_fl_content));  

    }  

    @Override  
    public void initData(Bundle bundle) {  
        this.mBundle = bundle;  
    }  

    @Override  
    public void loadData() {  
        setTitle(title);  
        String url = "file:///android_asset/apps/H5F563BDD/www/" + pageUrl + "?userKey=" + ShopConfigure.getInstance().getUserKey() + "&" + extras;  
        webview = SDK.createWebview(this, url,(pType, pArgs) -> {  
            switch (pType) {  
                case IWebviewStateListener.ON_WEBVIEW_READY:  
                    // 准备完毕之后添加webview到显示父View中,设置排版不显示状态,避免显示webview时,html内容排版错乱问题  
                    ((IWebview) pArgs).obtainFrameView().obtainMainView().setVisibility(View.INVISIBLE);  
                    SDK.attach(activity_shop_h5_web_fl_content, ((IWebview) pArgs));  
                    break;  
                case IWebviewStateListener.ON_PAGE_STARTED:  
                    // 首页面开始加载事件  
                    break;  
                case IWebviewStateListener.ON_PROGRESS_CHANGED:  
                    // 首页面加载进度变化  
                    break;  
                case IWebviewStateListener.ON_PAGE_FINISHED:  
                    // 页面加载完毕,设置显示webview  
                    webview.obtainFrameView().obtainMainView().setVisibility(View.VISIBLE);  
                    break;  
            }  
            return null;  
        });  
    }  

    @Override  
    protected void getIntentExtras(Intent intent) {  
        super.getIntentExtras(intent);  
        if (EmptyUtils.isNotEmpty(intent)) {  
            extras = intent.getStringExtra("extras");  
            title = intent.getStringExtra("title");  
            pageUrl = intent.getStringExtra("url");  
        }  
    }  

    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        return mEntryProxy.onActivityExecute(this, SysEventType.onCreateOptionMenu, menu);  
    }  

    @Override  
    public void onPause() {  
        super.onPause();  
        mEntryProxy.onPause(this);  
    }  

    @Override  
    public void onResume() {  
        super.onResume();  
        mEntryProxy.onResume(this);  
    }  

    public void onNewIntent(Intent intent) {  
        super.onNewIntent(intent);  
        if (intent.getFlags() != 0x10600000) {// 非点击icon调用activity时才调用newintent事件  
            mEntryProxy.onNewIntent(this, intent);  
        }  
    }  

    @Override  
    protected void onDestroy() {  
        super.onDestroy();  
        mEntryProxy.onStop(this);  
    }  

    @Override  
    public boolean onKeyDown(int keyCode, KeyEvent event) {  
        boolean _ret = mEntryProxy.onActivityExecute(this, SysEventType.onKeyDown, new Object[]{keyCode, event});  
        return _ret ? _ret : super.onKeyDown(keyCode, event);  
    }  

    @Override  
    public boolean onKeyUp(int keyCode, KeyEvent event) {  
        boolean _ret = mEntryProxy.onActivityExecute(this, SysEventType.onKeyUp, new Object[]{keyCode, event});  
        return _ret ? _ret : super.onKeyUp(keyCode, event);  
    }  

    @Override  
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {  
        boolean _ret = mEntryProxy.onActivityExecute(this, SysEventType.onKeyLongPress, new Object[]{keyCode, event});  
        return _ret ? _ret : super.onKeyLongPress(keyCode, event);  
    }  

    public void onConfigurationChanged(Configuration newConfig) {  
        try {  
            int temp = this.getResources().getConfiguration().orientation;  
            if (mEntryProxy != null) {  
                mEntryProxy.onConfigurationChanged(this, temp);  
            }  
            super.onConfigurationChanged(newConfig);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        mEntryProxy.onActivityExecute(this, SysEventType.onActivityResult, new Object[]{requestCode, resultCode, data});  
    }  

}  

第一个页面,打开正常


第二个页面打开,页面变成和第一个页面相同


并且在第二个界面点击返回后,第一个界面变成空白页。

调试发现
webview = SDK.createWebview(this, url,(pType, pArgs)
中,第二次页面的pArgs 里面的数值和第一次打开的值是一样的,并没有随着url改变。
不知道哪里出问题了????

2017-10-24 17:43 添加评论 分享
已邀请:
1

找到解决方法了:
SDK.createWebview(this, url,appid,(pType, pArgs)
只要保证每个页面的 appid 不同,就不会出现那个问题。

0

1026938865@qq.com

赞同来自:

大佬你的页面部分尼?? 只需要后面这些????

要回复问题请先登录注册