美文网首页
Cordova入门浅析

Cordova入门浅析

作者: Frank_Kivi | 来源:发表于2018-12-03 17:51 被阅读5次

    目录结构

    查看安卓的项目,只有两个module:
    app和CordovaLib;

    image.png

    入口

    代码的入口,只有一个就是MainActivity;

    public class MainActivity extends CordovaActivity
    {
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
    
            // enable Cordova apps to be started in the background
            Bundle extras = getIntent().getExtras();
            if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
                moveTaskToBack(true);
            }
    
            // Set by <content src="index.html" /> in config.xml  
            这是重点。
            loadUrl(launchUrl);
        }
    }
    

    查看方法:

     /**
         * Load the url into the webview.
         */
        可以直接认为是使用cordova自定义的WebView来加载一个url
        public void loadUrl(String url) {
            if (appView == null) {
                init();
            }
    
            // If keepRunning
            this.keepRunning = preferences.getBoolean("KeepRunning", true);
    
            appView.loadUrlIntoView(url, true);
        }
    
    
      @SuppressWarnings("deprecation")
        protected void loadConfig() {
            ConfigXmlParser parser = new ConfigXmlParser();
            parser.parse(this);
            preferences = parser.getPreferences();
            preferences.setPreferencesBundle(getIntent().getExtras());  
          在父类中进行了赋值
            launchUrl = parser.getLaunchUrl();
            pluginEntries = parser.getPluginEntries();
            Config.parser = parser;
        }
    

    继续向上找:

        其实就是加载了asset下边的index.html.
        private String launchUrl = "file:///android_asset/www/index.html";
        private CordovaPreferences prefs = new CordovaPreferences();
        private ArrayList<PluginEntry> pluginEntries = new ArrayList<PluginEntry>(20);
    
        public CordovaPreferences getPreferences() {
            return prefs;
        }
    
        public ArrayList<PluginEntry> getPluginEntries() {
            return pluginEntries;
        }
    
        public String getLaunchUrl() {
            return launchUrl;
        }
    

    而assets就是我们写的代码。


    image.png

    相关文章

      网友评论

          本文标题:Cordova入门浅析

          本文链接:https://www.haomeiwen.com/subject/maqucqtx.html