lvshuchengyin opened a new issue #2846: weex_sdk:0.26 show white screen
URL: https://github.com/apache/incubator-weex/issues/2846
 
 
   I try to use weex_sdk:0.26 to run a android demo, but the android app show 
nothing, just a white screen which mean after SplashActivity, the 
WXPageActivity show empty content.
   I think maybe  initialization doesn't correct.
   I try to find some demo but doesn't get it, only can find weex_sdk:0.16 
version but not 0.26, and the api has been change in 0.26. So I copy the code 
from weex_playground try to make it work, but fail.
   Could someone help me do some check? 
   Thanks!
   
   WXPageActivity.java
   ``` java
   package com.simpledao.book;
   
   import android.app.Activity;
   import android.app.AlertDialog;
   import android.content.BroadcastReceiver;
   import android.content.Context;
   import android.content.Intent;
   import android.content.IntentFilter;
   import android.graphics.PixelFormat;
   import android.graphics.Rect;
   import android.net.Uri;
   import android.os.Bundle;
   import android.support.annotation.NonNull;
   import android.support.annotation.Nullable;
   import android.support.v7.app.ActionBar;
   import android.text.TextUtils;
   import android.util.Log;
   import android.view.KeyEvent;
   import android.view.View;
   import android.widget.FrameLayout;
   import android.widget.Toast;
   
   import com.simpledao.book.util.AppConfig;
   import com.taobao.weex.IWXRenderListener;
   import com.taobao.weex.RenderContainer;
   import com.taobao.weex.WXSDKInstance;
   import com.taobao.weex.common.WXRenderStrategy;
   import com.taobao.weex.ui.component.NestedContainer;
   import com.taobao.weex.utils.WXFileUtils;
   
   import java.io.File;
   import java.util.HashMap;
   
   public class WXPageActivity extends WXBaseActivity
           implements IWXRenderListener, 
WXSDKInstance.NestedInstanceInterceptor {
   
       private static final String TAG = "WXPageActivity";
   
       private FrameLayout mContentView;
   
       private BroadcastReceiver mReceiver;
       private Uri mUri;
       private WXSDKInstance mInstance;
       private HashMap<String, Object> mConfigMap = new HashMap<>();
       private WXAnalyzerDelegate mWxAnalyzerDelegate;
   
       @Override
       protected void onCreate(@Nullable Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_wxpage);
   //        WXSDKEngine.setActivityNavBarSetter(new NavigatorAdapter());
           getWindow().setFormat(PixelFormat.TRANSLUCENT);
   
           mUri = Uri.parse(AppConfig.getLaunchUrl());
   
           initUIViews();
           loadPageFromUri();
       }
   
   
       private void loadPageFromUri() {
           loadWXFromLocal(false);
   
           mInstance.onActivityCreate();
           registerBroadcastReceiver();
           mWxAnalyzerDelegate = new WXAnalyzerDelegate(this);
           mWxAnalyzerDelegate.onCreate();
       }
   
   
       private void loadWXFromLocal(boolean reload) {
           if (reload && mInstance != null) {
               mInstance.destroy();
               mInstance = null;
           }
           if (mInstance == null) {
               RenderContainer renderContainer = new RenderContainer(this);
               mInstance = new WXSDKInstance(this);
               mInstance.setRenderContainer(renderContainer);
               mInstance.registerRenderListener(this);
               mInstance.setNestedInstanceInterceptor(this);
               mInstance.setTrackComponent(true);
           }
           mContentView.post(new Runnable() {
               @Override
               public void run() {
                   Activity ctx = WXPageActivity.this;
                   Rect outRect = new Rect();
                   
ctx.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
                   mConfigMap.put(WXSDKInstance.BUNDLE_URL, mUri.toString());
                   String path = "file".equals(mUri.getScheme()) ?
                           assembleFilePath(mUri) : mUri.toString();
                   mInstance.render(path, WXFileUtils.loadAsset(path, ctx),
                           mConfigMap, null, WXRenderStrategy.APPEND_ASYNC);
               }
           });
       }
   
       private String assembleFilePath(Uri uri) {
           if (uri != null && uri.getPath() != null) {
               return uri.getPath().replaceFirst("/", "");
           }
           return "";
       }
   
   
       private void initUIViews() {
           mContentView = findViewById(R.id.container);
           ActionBar actionBar = getSupportActionBar();
           if (actionBar != null) {
               actionBar.setDisplayHomeAsUpEnabled(true);
               String title = mUri.toString().substring(mUri.toString()
                       .lastIndexOf(File.separator) + 1);
               actionBar.setTitle(title);
           }
       }
   
       private void registerBroadcastReceiver() {
           mReceiver = new RefreshBroadcastReceiver();
           IntentFilter filter = new IntentFilter();
           filter.addAction(WXSDKInstance.ACTION_DEBUG_INSTANCE_REFRESH);
           filter.addAction(WXSDKInstance.ACTION_INSTANCE_RELOAD);
           registerReceiver(mReceiver, filter);
       }
   
       private void unregisterBroadcastReceiver() {
           if (mReceiver != null) {
               unregisterReceiver(mReceiver);
           }
           mReceiver = null;
       }
   
       @Override
       public void onStart() {
           super.onStart();
           if (mInstance != null) {
               mInstance.onActivityStart();
           }
           if (mWxAnalyzerDelegate != null) {
               mWxAnalyzerDelegate.onStart();
           }
       }
   
       @Override
       public void onResume() {
           super.onResume();
           if (mInstance != null) {
               mInstance.onActivityResume();
           }
           if (mWxAnalyzerDelegate != null) {
               mWxAnalyzerDelegate.onResume();
           }
       }
   
       @Override
       protected void onPause() {
           super.onPause();
           if (mInstance != null) {
               mInstance.onActivityPause();
           }
           if (mWxAnalyzerDelegate != null) {
               mWxAnalyzerDelegate.onPause();
           }
       }
   
       @Override
       protected void onStop() {
           super.onStop();
           if (mInstance != null) {
               mInstance.onActivityStop();
           }
           if (mWxAnalyzerDelegate != null) {
               mWxAnalyzerDelegate.onStop();
           }
       }
   
       @Override
       public void onBackPressed() {
           if (!mInstance.onBackPressed()) {
               super.onBackPressed();
           }
       }
   
       @Override
       public void onDestroy() {
           if (mInstance != null) {
               mInstance.onActivityDestroy();
           }
           mContentView = null;
           unregisterBroadcastReceiver();
           if (mWxAnalyzerDelegate != null) {
               mWxAnalyzerDelegate.onDestroy();
           }
           super.onDestroy();
       }
   
       @Override
       public boolean onKeyUp(int keyCode, KeyEvent event) {
           return (mWxAnalyzerDelegate != null && 
mWxAnalyzerDelegate.onKeyUp(keyCode, event))
                   || super.onKeyUp(keyCode, event);
       }
   
       @Override
       public void onRequestPermissionsResult(int requestCode, @NonNull 
String[] permissions,
                                              @NonNull int[] grantResults) {
           super.onRequestPermissionsResult(requestCode, permissions, 
grantResults);
           if (mInstance != null) {
               mInstance.onRequestPermissionsResult(requestCode, permissions, 
grantResults);
           }
       }
   
       @Override
       protected void onActivityResult(int requestCode, int resultCode, Intent 
data) {
           super.onActivityResult(requestCode, resultCode, data);
           if (mInstance != null) {
               mInstance.onActivityResult(requestCode, resultCode, data);
           }
       }
   
       @Override
       public void onViewCreated(WXSDKInstance instance, View view) {
           View wrappedView = null;
           if (mWxAnalyzerDelegate != null) {
               wrappedView = mWxAnalyzerDelegate.onWeexViewCreated(instance, 
view);
           }
           if (wrappedView != null) {
               view = wrappedView;
           }
           if (view.getParent() == null) {
               mContentView.addView(view);
           }
           mContentView.requestLayout();
       }
   
       @Override
       public void onRenderSuccess(WXSDKInstance instance, int width, int 
height) {
           if (mWxAnalyzerDelegate != null) {
               mWxAnalyzerDelegate.onWeexRenderSuccess(instance);
           }
       }
   
       @Override
       public void onRefreshSuccess(WXSDKInstance instance, int width, int 
height) {
       }
   
       @Override
       public void onException(WXSDKInstance instance, String errCode, String 
msg) {
           if (mWxAnalyzerDelegate != null) {
               mWxAnalyzerDelegate.onException(instance, errCode, msg);
           }
           if (!TextUtils.isEmpty(errCode) && errCode.contains("|")) {
               String[] errCodeList = errCode.split("\\|");
               String code = errCodeList[1];
               String codeType = errCode.substring(0, errCode.indexOf("|"));
               if (TextUtils.equals("1", codeType)) {
                   String errMsg = "codeType:" + codeType + "\n" + " errCode:" 
+ code + "\n" +
                           " ErrorInfo:" + msg;
                   degradeAlert(errMsg);
               } else {
                   Toast.makeText(getApplicationContext(), "errCode:" + errCode 
+
                           " Render ERROR:" + msg, Toast.LENGTH_SHORT).show();
               }
           }
       }
   
       private void degradeAlert(String errMsg) {
           new AlertDialog.Builder(this)
                   .setTitle("Downgrade success")
                   .setMessage(errMsg)
                   .setPositiveButton("OK", null)
                   .show();
       }
   
       @Override
       public void onCreateNestInstance(WXSDKInstance instance, NestedContainer 
container) {
           Log.d(TAG, "Nested Instance created.");
       }
   
       public class RefreshBroadcastReceiver extends BroadcastReceiver {
           @Override
           public void onReceive(Context context, Intent intent) {
               if 
(WXSDKInstance.ACTION_INSTANCE_RELOAD.equals(intent.getAction()) ||
                       
WXSDKInstance.ACTION_DEBUG_INSTANCE_REFRESH.equals(intent.getAction())) {
                   String myUrl = intent.getStringExtra("url");
                   if (mUri != null) {
                       loadWXFromLocal(true);
                   }
               }
           }
       }
   }
   ```
   
   ``` xml
   <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android";
       xmlns:app="http://schemas.android.com/apk/res-auto";
       xmlns:tools="http://schemas.android.com/tools";
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:fitsSystemWindows="true"
       tools:context="com.simpledao.book.WXPageActivity">
   
       <FrameLayout
           android:id="@+id/container"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:background="#aaaaaa">
   
       </FrameLayout>
   
   </FrameLayout>
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to