-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1 lines (1 loc) · 43.6 KB
/
index.html
1
<!DOCTYPE html><html class="theme-next pisces" lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta name="theme-color" content="#fff"><link rel="preload" href="https://fastly.jsdelivr.net/gh/DIYgod/hexo-theme-sagiri/source/fonts/Candyshop.otf" as="font" type="font/otf" crossorigin="anonymous"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"><link href="https://fastly.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css"><link href="https://fastly.jsdelivr.net/npm/social-share.js@1.0.16/dist/css/share.min.css" rel="stylesheet" type="text/css"><link href="/blog/css/main.css?v=1.0.1" rel="stylesheet" type="text/css"><link rel="apple-touch-icon" sizes="180x180" href="/blog/apple-touch-icon.png?v=1.0.1"><link rel="icon" type="image/png" sizes="32x32" href="/blog/favicon.png?v=1.0.1"><link rel="mask-icon" href="/blog/safari-pinned-tab.svg?v=1.0.1" color="#fff"><link rel="manifest" href="/blog/manifest.json"><meta name="keywords" content="DIYgod,blog"><link rel="alternate" href="/blog/atom.xml" title="Hi! Xianxin" type="application/atom+xml"><meta name="description" content="网络个人自留地,更多的使用Obsidian笔记,这里更新随缘。.."><meta property="og:type" content="website"><meta property="og:title" content="Hi! Xianxin"><meta property="og:url" content="https://houxianxin.github.io/blog/"><meta property="og:site_name" content="Hi! Xianxin"><meta property="og:description" content="网络个人自留地,更多的使用Obsidian笔记,这里更新随缘。.."><meta property="og:locale"><meta property="article:author" content="侯宪鑫"><meta property="article:tag" content="编程,开发,全栈技能,安全,产品,运营,算法,人工智能,前端,后端,小程序,app,自媒体,网络营销,副业,seo,android,ios,mac,windows,linux,web,java,nodejs,python,golang,php,harmonyos,h5,html,css,js,vue,react,angular,markdown,易语言,github,工作流,效率工具,被动收入,程序员赚钱,网赚项目,google adsence,引流,流量变现,个人成长,GTD,番茄工作法,时间管理,知识管理,个人知识体系,Affiliate,Media Buy,Niche,基金,股票,cps"><meta name="twitter:card" content="summary"><script type="text/javascript" id="hexo.configurations">var NexT=window.NexT||{},CONFIG={root:"",scheme:"Pisces",version:"1.0.1",sidebar:{position:"right",display:"always",offset:52,b2t:!1,scrollpercent:!1,onmobile:!1},fancybox:!1,tabs:!0,motion:{enable:!1,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}},since:"3/20/2015 12:00:00",site:{title:"",subtitle:"",author:""},duoshuo:{userId:"0",author:"博主"},algolia:{applicationID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}},leancloud:{enable:!1,appID:"",appKey:""},favicon:{visibilitychange:!0,narmal:"/favicon.png",hidden:"/failure.ico",show_text:"(/≧▽≦/)咦!又好了!",hide_text:"(●—●)喔哟,崩溃啦!"}}</script><script type="text/javascript" src="https://fastly.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script><script type="text/javascript" src="https://fastly.jsdelivr.net/npm/disqusjs@1.2.2/dist/disqus.js"></script><link rel="canonical" href="https://houxianxin.github.io/blog/"><title>Hi! Xianxin</title><meta name="generator" content="Hexo 5.4.2"></head><body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans" class="theme-darling"><div class="container sidebar-position-right page-home"><header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-首页"><a href="/blog/" rel="section"><i class="menu-item-icon fas fa-meteor"></i><br>首页</a></li><li class="menu-item menu-item-归档"><a href="/blog/archives/" rel="section"><i class="menu-item-icon fas fa-archive"></i><br>归档</a></li><li class="menu-item menu-item-标签"><a href="/blog/tags/" rel="section"><i class="menu-item-icon fas fa-tag"></i><br>标签</a></li><li class="menu-item menu-item-小伙伴"><a href="/blog/friends/" rel="section"><i class="menu-item-icon fas fa-mars-stroke"></i><br>小伙伴</a></li><li class="menu-item menu-item-留言板"><a href="/blog/message/" rel="section"><i class="menu-item-icon fas fa-comment-dots"></i><br>留言板</a></li><li class="menu-item menu-item-关于我"><a href="/blog/about/" rel="section"><i class="menu-item-icon fas fa-heartbeat"></i><br>关于我</a></li><li class="menu-item search"><a href="javascript:;" class="popup-trigger"><i class="fas fa-search"></i><br>搜索</a></li></ul><div class="site-search"><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class="search-icon"><i class="fa fa-search"></i> </span><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span><div class="local-search-input-wrapper"><input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input"></div></div><div id="local-search-result"></div></div></div></nav><div class="site-brand-wrapper"><div class="site-brand-bg"><picture><source srcset="https://fastly.jsdelivr.net/gh/DIYgod/hexo-theme-sagiri/source/images/header-gyx-s.webp" type="image/webp" media="(max-width: 500px)"><source srcset="https://fastly.jsdelivr.net/gh/DIYgod/hexo-theme-sagiri/source/images/header-gyx-s.png" type="image/png" media="(max-width: 500px)"><source srcset="https://fastly.jsdelivr.net/gh/DIYgod/hexo-theme-sagiri/source/images/header-gyx.webp" type="image/webp"><img loading="lazy" src="https://fastly.jsdelivr.net/gh/DIYgod/hexo-theme-sagiri/source/images/header-gyx.png"></picture></div><div class="site-meta"><div class="custom-logo-site-title"><div class="brand"><span class="logo-line-before"><i></i></span><div class="site-title"><div id="animate-stroke" class="animate"><span><svg><use xlink:href="#strokeH"></use></svg> </span><span><svg><use xlink:href="#strokei"></use></svg> </span><span><svg><use xlink:href="#stroke!"></use></svg> </span><span><svg><use xlink:href="#stroke "></use></svg> </span><span><svg><use xlink:href="#strokeX"></use></svg> </span><span><svg><use xlink:href="#strokei"></use></svg> </span><span><svg><use xlink:href="#strokea"></use></svg> </span><span><svg><use xlink:href="#stroken"></use></svg> </span><span><svg><use xlink:href="#strokex"></use></svg> </span><span><svg><use xlink:href="#strokei"></use></svg> </span><span><svg><use xlink:href="#stroken"></use></svg></span></div><div id="animate" class="animate"><span><svg><text id="strokeH">H</text></svg> </span><span><svg><text id="strokei">i</text></svg> </span><span><svg><text id="stroke!">!</text></svg> </span><span><svg><text id="stroke "></text></svg> </span><span><svg><text id="strokeX">X</text></svg> </span><span><svg><text id="strokei">i</text></svg> </span><span><svg><text id="strokea">a</text></svg> </span><span><svg><text id="stroken">n</text></svg> </span><span><svg><text id="strokex">x</text></svg> </span><span><svg><text id="strokei">i</text></svg> </span><span><svg><text id="stroken">n</text></svg></span></div><div id="guide" class="guide"><span>H</span><span>i</span><span>!</span><span> </span><span>X</span><span>i</span><span>a</span><span>n</span><span>x</span><span>i</span><span>n</span></div></div><span class="logo-line-after"><i></i></span></div></div><p class="site-subtitle">持续行动,持续进步!</p></div><div class="site-nav-toggle"><button><span class="btn-bar"></span> <span class="btn-bar"></span> <span class="btn-bar"></span></button></div></div><div class="site-master" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-master-avatar scaleup" itemprop="image" src="/blog/favicon.png" alt=""><h2 class="site-master-description scaleup" itemprop="description">写代码是热爱,写到世界充满爱!</h2></div></div></header><main id="main" class="main"><div class="main-inner"><div class="content-wrap"><div id="content" class="content"><section id="posts" class="posts-expand"><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">09月</div><div class="post-day">29</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/JavaScript/" itemprop="url" rel="index"><span itemprop="name">JavaScript</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2021-09-29-js%E4%BE%A6%E6%B5%8B%E6%89%8B%E6%9C%BA%E6%B5%8F%E8%A7%88%E5%99%A8/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2021-09-29-js%E4%BE%A6%E6%B5%8B%E6%89%8B%E6%9C%BA%E6%B5%8F%E8%A7%88%E5%99%A8/" itemprop="url">JS侦测手机浏览器的几种方法</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2021-09-29T00:00:00+08:00">2021-09-29</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">1190</span></span></div></header><div class="post-body" itemprop="articleBody"><p>有时候,前端网页需要知道,用户使用的是手机浏览器还是桌面浏览器。</p><p>本文根据 StackOverflow,整理了 JavaScript 侦测手机浏览器的五种方法。</p><h2 id="一、navigator-userAgent"><a href="#一、navigator-userAgent" class="headerlink" title="一、navigator.userAgent"></a>一、navigator.userAgent</h2><p>最简单的方法就是分析浏览器的 user agent 字符串,它包含了设备信息。</p><div class="post-button text-center"><a class="btn scaleup" href="/blog/2021-09-29-js%E4%BE%A6%E6%B5%8B%E6%89%8B%E6%9C%BA%E6%B5%8F%E8%A7%88%E5%99%A8/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">06月</div><div class="post-day">27</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/Docker/" itemprop="url" rel="index"><span itemprop="name">Docker</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2021-06-27-Docker%E5%85%A5%E9%97%A8/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2021-06-27-Docker%E5%85%A5%E9%97%A8/" itemprop="url">Docker 入门</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2021-06-27T20:59:39+08:00">2021-06-27</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">2447</span></span></div></header><div class="post-body" itemprop="articleBody"><p><img src="https://www.ruanyifeng.com/blogimg/asset/2018/bg2018020901.png" alt="docker"></p><div class="post-button text-center"><a class="btn scaleup" href="/blog/2021-06-27-Docker%E5%85%A5%E9%97%A8/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">09月</div><div class="post-day">15</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/React/" itemprop="url" rel="index"><span itemprop="name">React</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2020-09-15-React%20hook2/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2020-09-15-React%20hook2/" itemprop="url">React Hook 再探索</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-09-15T00:00:00+08:00">2020-09-15</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">2198</span></span></div></header><div class="post-body" itemprop="articleBody"><p>最近逐渐体会到 React 钩子(hooks)非常好用,感觉重新认识了 React 这个框架。</p><p>下面就来谈谈,怎样正确理解钩子,并且深入剖析最重要的钩子之一的useEffect()。内容会尽量通俗,让不熟悉 React 的朋友也能看懂。</p><h2 id="一、React-的两套-API"><a href="#一、React-的两套-API" class="headerlink" title="一、React 的两套 API"></a>一、React 的两套 API</h2><p>以前,React API 只有一套,现在有两套:类(class)API 和基于函数的钩子(hooks) API。</p><div class="post-button text-center"><a class="btn scaleup" href="/blog/2020-09-15-React%20hook2/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">06月</div><div class="post-day">02</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/React-Native/" itemprop="url" rel="index"><span itemprop="name">React Native</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2020-06-02-RN%20metro/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2020-06-02-RN%20metro/" itemprop="url">ReactNative Metro 打包浅析</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-06-02T00:00:00+08:00">2020-06-02</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">1021</span></span></div></header><div class="post-body" itemprop="articleBody"><h2 id="Metro是什么"><a href="#Metro是什么" class="headerlink" title="Metro是什么"></a>Metro是什么</h2><p>metro 是一个针对 React Native的JavaScript模块打包器,他接收一个entry file (入口文件) 和一些配置作为参数,返回给你一个单独的JavaScript文件,这个文件包含了你写的所有的JavaScript 代码和所有的依赖。</p><p>也就是说Metro把你写的几十上百个js文件和几百个node_modules的依赖,打包成了一个文件。</p><div class="post-button text-center"><a class="btn scaleup" href="/blog/2020-06-02-RN%20metro/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">09月</div><div class="post-day">01</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/React/" itemprop="url" rel="index"><span itemprop="name">React</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2019-09-01-React%20hook1/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2019-09-01-React%20hook1/" itemprop="url">React Hook 入门</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-01T00:00:00+08:00">2019-09-01</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">1937</span></span></div></header><div class="post-body" itemprop="articleBody"><p>React 是主流的前端框架,v16.8 版本引入了全新的 API,叫做 React Hooks,颠覆了以前的用法。</p><p>这个 API 是 React 的未来,有必要深入理解。本文谈谈我的理解,简单介绍它的用法,帮助大家快速上手。</p><p>阅读本文需要有 React 基础。如果你还没学会 React,可以先看一下它的教程。</p><h2 id="一、组件类的缺点"><a href="#一、组件类的缺点" class="headerlink" title="一、组件类的缺点"></a>一、组件类的缺点</h2><p>React 的核心是组件。v16.8 版本之前,组件的标准写法是类(class)。下面是一个简单的组件类。</p><div class="post-button text-center"><a class="btn scaleup" href="/blog/2019-09-01-React%20hook1/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">10月</div><div class="post-day">28</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2018-10-28-Android%20View%E7%BB%98%E5%88%B6%E6%B5%81%E7%A8%8B/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2018-10-28-Android%20View%E7%BB%98%E5%88%B6%E6%B5%81%E7%A8%8B/" itemprop="url">Android View 绘制流程</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-28T00:00:00+08:00">2018-10-28</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">2520</span></span></div></header><div class="post-body" itemprop="articleBody"><h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>作为一名Android开发者肯定明白View的地位,说它占据半壁江山也不为过,作为基石之一,搞明白它的加载流程是每个开发者都应该去做的,目前网络上很多关于View绘制流程的文章,有些质量也很高,但我还是想以自己的思路出一篇文章。相信读完你对View的工作机制以及自定义View会有一个全新的认识。</p><h2 id="1-View的绘制时机"><a href="#1-View的绘制时机" class="headerlink" title="1. View的绘制时机"></a>1. View的绘制时机</h2><h3 id="1-1-知识储备"><a href="#1-1-知识储备" class="headerlink" title="1.1. 知识储备"></a>1.1. 知识储备</h3><ul><li>Window:每个Activity都会创建一个Window用于承载View视图的显示,Window是一个抽象类存在了一个唯一实现类PhoneWindow<div class="post-button text-center"><a class="btn scaleup" href="/blog/2018-10-28-Android%20View%E7%BB%98%E5%88%B6%E6%B5%81%E7%A8%8B/#more" rel="contents">阅读全文 »</a></div></li></ul></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">06月</div><div class="post-day">18</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2018-06-18-Android%20%E4%BA%8B%E4%BB%B6%E5%88%86%E5%8F%91%E6%9C%BA%E5%88%B61/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2018-06-18-Android%20%E4%BA%8B%E4%BB%B6%E5%88%86%E5%8F%91%E6%9C%BA%E5%88%B61/" itemprop="url">Android 触摸事件分发机制:事件如何到达Activity</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-06-18T00:00:00+08:00">2018-06-18</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">3079</span></span></div></header><div class="post-body" itemprop="articleBody"><h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>很高兴遇见你~</p><p>事件分发,android中一个老生常谈的话题了。本文要探究的是,一个触摸信息从系统底层产生之后,一步步到达Activity进行分发的整体流程。而关于系统底层的逻辑,不在本文的讨论范围内。主要的内容是分析触摸事件传递的路径。不会纠结于源码与底层,而是把触摸事件来源的大体流程呈现出来,便于对事件分发体系有个更加完整的理解。</p><div class="post-button text-center"><a class="btn scaleup" href="/blog/2018-06-18-Android%20%E4%BA%8B%E4%BB%B6%E5%88%86%E5%8F%91%E6%9C%BA%E5%88%B61/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">01月</div><div class="post-day">16</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2018-01-16-App%E7%9A%84%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2018-01-16-App%E7%9A%84%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B/" itemprop="url">App 启动流程</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-16T00:00:00+08:00">2018-01-16</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">4708</span></span></div></header><div class="post-body" itemprop="articleBody"><p><a target="_blank" rel="noopener" href="https://github.com/zhpanvip/AndroidNote/wiki/AMS%E6%A0%B8%E5%BF%83%E5%88%86%E6%9E%90">ActivityManagerService</a></p><h2 id="App启动流程分析"><a href="#App启动流程分析" class="headerlink" title="App启动流程分析"></a>App启动流程分析</h2><p>AndroidManifest文件中配置默认启动的Activity:</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">activity</span> <span class="attr">android:name</span>=<span class="string">".MainActivity"</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">intent-filter</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">action</span> <span class="attr">android:name</span>=<span class="string">"android.intent.action.MAIN"</span> /></span></span><br><span class="line"></span><br><span class="line"> <span class="tag"><<span class="name">category</span> <span class="attr">android:name</span>=<span class="string">"android.intent.category.LAUNCHER"</span> /></span></span><br><span class="line"> <span class="tag"></<span class="name">intent-filter</span>></span></span><br><span class="line"><span class="tag"></<span class="name">activity</span>></span></span><br></pre></td></tr></table></figure><p>系统在启动时会启动PMS服务,解析所有APP的AndroidManifest文件,在Launcher启动的时候就会将APP的图标及启动信息封装,在点击桌面上的APP图标时则出发APP的启动流程。APP的启动流程时序图如下:</p><div class="post-button text-center"><a class="btn scaleup" href="/blog/2018-01-16-App%E7%9A%84%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">03月</div><div class="post-day">18</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/Android/" itemprop="url" rel="index"><span itemprop="name">Android</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2017-03-18-Activity%E7%9A%84%E5%90%AF%E5%8A%A8%E6%A8%A1%E5%BC%8F/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2017-03-18-Activity%E7%9A%84%E5%90%AF%E5%8A%A8%E6%A8%A1%E5%BC%8F/" itemprop="url">Activity的几种启动模式</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-18T00:00:00+08:00">2017-03-18</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">1599</span></span></div></header><div class="post-body" itemprop="articleBody"><h2 id="Activity的启动模式"><a href="#Activity的启动模式" class="headerlink" title="Activity的启动模式"></a>Activity的启动模式</h2><p>Android 提供了四种Activity启动方式:</p><h3 id="1-标准模式:standard"><a href="#1-标准模式:standard" class="headerlink" title="1.标准模式:standard"></a>1.标准模式:standard</h3><p>每启动一次Activity,就会创建一个新的Activity实例并置于栈顶。谁启动了这个Activity,那么这个Activity就运行在启动它的那个Activity所在的栈中。</p><div class="post-button text-center"><a class="btn scaleup" href="/blog/2017-03-18-Activity%E7%9A%84%E5%90%AF%E5%8A%A8%E6%A8%A1%E5%BC%8F/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-date"><div class="post-month">06月</div><div class="post-day">19</div></div><div class="post-badge"><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/%E9%9A%8F%E6%83%B3%E5%BD%95/" itemprop="url" rel="index"><span itemprop="name">随想录</span></a></span></div><div class="post-block"><link itemprop="mainEntityOfPage" href="https://houxianxin.github.io/blog/blog/2015-06-19-%E6%96%B0%E5%AE%B6%E8%90%BD%E6%88%90%EF%BC%8C%E6%AC%A2%E8%BF%8E%E5%81%9A%E5%AE%A2/"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content=""><meta itemprop="description" content=""><meta itemprop="image" content="/blog/favicon.png"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="Hi! Xianxin"></span><header class="post-header"><h1 class="post-title" itemprop="name headline"><a class="post-title-link scaleup" href="/blog/2015-06-19-%E6%96%B0%E5%AE%B6%E8%90%BD%E6%88%90%EF%BC%8C%E6%AC%A2%E8%BF%8E%E5%81%9A%E5%AE%A2/" itemprop="url">新家落成,欢迎做客</a></h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="far fa-calendar"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2015-06-19T22:26:48+08:00">2015-06-19</time> </span><span class="post-wordcount"><span class="post-meta-divider">•</span> <span class="post-meta-item-icon"><i class="far fa-file-word"></i> </span><span class="post-meta-item-text">字数统计</span> <span title="字数统计">10</span></span></div></header><div class="post-body" itemprop="articleBody"><p>新家落成,欢迎常来做客!</p><link rel="stylesheet" href="/css/markmap.css" type="text/css"><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css"><div class="post-button text-center"><a class="btn scaleup" href="/blog/2015-06-19-%E6%96%B0%E5%AE%B6%E8%90%BD%E6%88%90%EF%BC%8C%E6%AC%A2%E8%BF%8E%E5%81%9A%E5%AE%A2/#more" rel="contents">阅读全文 »</a></div></div><footer class="post-footer"></footer></div></article></section></div><link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css"><script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script></div><div class="sidebar-toggle"><div class="sidebar-toggle-line-wrap"><span class="sidebar-toggle-line sidebar-toggle-line-first"></span> <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span> <span class="sidebar-toggle-line sidebar-toggle-line-last"></span></div></div><aside id="sidebar" class="sidebar"><div class="sidebar-inner"><section class="site-overview-wrap sidebar-panel sidebar-panel-active"><div class="site-overview"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" src="https://fastly.jsdelivr.net/gh/DIYgod/hexo-theme-sagiri/source/images/card-avatar2.jpeg" alt=""><p class="site-author-name" itemprop="name"><span style="opacity:.2">网红</span>houxianxin</p><p class="site-description motion-element" itemprop="description">你能抓到我么?</p></div><div class="links-of-author motion-element"><span class="links-of-author-item scaleup"><a href="https://github.com/houxianxin" target="_blank" title="GitHub"><i class="fab fa-github" style="color:#191717"><span>houxianxin</span></i></a> </span><span class="links-of-author-item scaleup"><a href="/atom.xml" target="_blank" title="RSS"><i style="fill:#f78422"><svg t="1581190724531" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="16212"><path d="M512 0a512 512 0 1 0 512 512A512 512 0 0 0 512 0z m-130.72 736a71.84 71.84 0 0 1-38.72 38.4 74.24 74.24 0 0 1-56.8 0 72.64 72.64 0 0 1-38.4-38.4 73.44 73.44 0 0 1 16-80 72.48 72.48 0 0 1 22.88-16 72.96 72.96 0 0 1 96 96z m192 32a51.84 51.84 0 0 1-88.32-36.64 187.52 187.52 0 0 0-15.2-75.04 194.08 194.08 0 0 0-102.72-102.72 186.72 186.72 0 0 0-75.04-15.2 51.84 51.84 0 0 1 0-103.52 284.64 284.64 0 0 1 115.2 23.52 300.64 300.64 0 0 1 157.76 157.76 284.96 284.96 0 0 1 23.52 115.2 49.92 49.92 0 0 1-15.52 37.44z m195.84 0a51.84 51.84 0 0 1-88.48-36.64 378.72 378.72 0 0 0-13.92-103.2 393.92 393.92 0 0 0-39.2-92.96 389.92 389.92 0 0 0-232.48-177.76 380 380 0 0 0-103.2-13.92 51.84 51.84 0 0 1-36.64-88.48 49.92 49.92 0 0 1 36.48-15.04 483.2 483.2 0 0 1 130.72 17.6 494.08 494.08 0 0 1 344 344 483.2 483.2 0 0 1 17.6 130.72 50.08 50.08 0 0 1-15.2 36.48z" p-id="16213"></path></svg><span>RSS</span></i></a></span></div><div class="des-of-author"><div class="des-of-author-nav"><div class="des-of-author-title active" data-index="1">本站介绍</div><div class="des-of-author-title" data-index="2">最喜欢的女孩子</div><div class="des-of-author-title" data-index="3">专注的领域</div><div class="des-of-author-title" data-index="4">装备</div><div class="des-of-author-title" data-index="5">工作</div></div><div class="des-of-author-panel"><div class="des-of-author-des active" data-index="1">网络个人自留地,更多的使用Obsidian笔记,这里更新随缘。..</div><div class="des-of-author-des" data-index="2">老婆啦~~</div><div class="des-of-author-des" data-index="3">Android原生应用层开发、React Native/Flutter跨平台开发、Web开发/React/Vue、小程序开发...</div><div class="des-of-author-des" data-index="4">好久没更新啦..MacBook PRO、Windows PC、Redmi K30、iPhone7、Apple Watch、AirPods、Logi MX...</div><div class="des-of-author-des" data-index="5">前Sengled Android开发工程师。待业中...</div></div></div><details class="views-top-wrap"><summary class="views-top-name scaleup">看爆 Top5</summary><ul class="views-top"></ul></details></div></section></div></aside></div></main><footer id="footer" class="footer"><div class="footer-image"><img src="https://fastly.jsdelivr.net/gh/DIYgod/hexo-theme-sagiri/source/images/footer.png"></div><div class="footer-inner"><p>本站已萌萌哒运行<span id="since"></span><span class="my-face">(●'◡'●)ノ♥</span></p><p>© <span itemprop="copyrightYear">2022</span> Hi! Xianxin. 由 <a href="https://hexo.io/" target="_blank" class="external" rel="nofollow">Hexo</a> 强力驱动. Theme By <a href="https://github.com/DIYgod/hexo-theme-sagiri" target="_blank" class="external" rel="nofollow">Sagiri</a> v1.0.1. <a href="/blog/sitemap.xml" target="_blank">站点地图</a>.</p><p>Made with <i class="fas fa-heart throb" style="color:#d43f57"></i> by <span class="author" itemprop="copyrightHolder">侯宪鑫</span>.</p></div></footer><div class="back-to-top"><img src="https://fastly.jsdelivr.net/gh/DIYgod/hexo-theme-sagiri/source/images/scroll.png"></div><canvas id="evanyou"></canvas></div><script type="text/javascript" src="/blog/js/sagiri.min.js?v=1.0.1"></script><script type="text/javascript">var isfetched=!1,isXml=!0,search_path="search.xml";0===search_path.length?search_path="search.xml":/json$/i.test(search_path)&&(isXml=!1);var path="/blog/"+search_path,onPopupClose=function(t){$(".popup").hide(),$("#local-search-input").val(""),$(".search-result-list").remove(),$("#no-result").remove(),$(".local-search-pop-overlay").remove(),$("body").css("overflow","")};function proceedsearch(){$("body").append('<div class="search-popup-overlay local-search-pop-overlay"></div>').css("overflow","hidden"),$(".search-popup-overlay").click(onPopupClose),$(".popup").toggle();var t=$("#local-search-input");t.attr("autocapitalize","none"),t.attr("autocorrect","off"),t.focus()}var searchFunc=function(t,e,o){"use strict";$("body").append('<div class="search-popup-overlay local-search-pop-overlay"><div id="search-loading-icon"><i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i></div></div>').css("overflow","hidden"),$("#search-loading-icon").css("margin","20% auto 0 auto").css("text-align","center"),$.ajax({url:t,dataType:isXml?"xml":"json",async:!0,success:function(t){isfetched=!0,$(".popup").detach().appendTo(".header-inner");var n=isXml?$("entry",t).map((function(){return{title:$("title",this).text(),content:$("content",this).text(),url:$("url",this).text()}})).get():t,r=document.getElementById(e),s=document.getElementById(o),a=function(){var t=r.value.trim().toLowerCase(),e=t.split(/[\s\-]+/);e.length>1&&e.push(t);var o=[];if(t.length>0&&n.forEach((function(n){var r=!1,s=0,a=0,i=n.title.trim(),c=i.toLowerCase(),l=n.content.trim().replace(/<[^>]+>/g,""),h=l.toLowerCase(),p=decodeURIComponent(n.url),u=[],f=[];if(""!=i&&(e.forEach((function(t){function e(t,e,o){var n=t.length;if(0===n)return[];var r=0,s=[],a=[];for(o||(e=e.toLowerCase(),t=t.toLowerCase());(s=e.indexOf(t,r))>-1;)a.push({position:s,word:t}),r=s+n;return a}u=u.concat(e(t,c,!1)),f=f.concat(e(t,h,!1))})),(u.length>0||f.length>0)&&(r=!0,s=u.length+f.length)),r){function d(e,o,n,r){for(var s=r[r.length-1],i=s.position,c=s.word,l=[],h=0;i+c.length<=n&&0!=r.length;){c===t&&h++,l.push({position:i,length:c.length});var p=i+c.length;for(r.pop();0!=r.length&&(i=(s=r[r.length-1]).position,c=s.word,p>i);)r.pop()}return a+=h,{hits:l,start:o,end:n,searchTextCount:h}}[u,f].forEach((function(t){t.sort((function(t,e){return e.position!==t.position?e.position-t.position:t.word.length-e.word.length}))}));var g=[];0!=u.length&&g.push(d(0,0,i.length,u));for(var v=[];0!=f.length;){var $=f[f.length-1],C=$.position,m=$.word,x=C-20,w=C+80;x<0&&(x=0),w<C+m.length&&(w=C+m.length),w>l.length&&(w=l.length),v.push(d(0,x,w,f))}v.sort((function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hits.length!==e.hits.length?e.hits.length-t.hits.length:t.start-e.start}));var y=parseInt("1");function T(t,e){var o="",n=e.start;return e.hits.forEach((function(e){o+=t.substring(n,e.position);var r=e.position+e.length;o+='<b class="search-keyword">'+t.substring(e.position,r)+"</b>",n=r})),o+=t.substring(n,e.end)}y>=0&&(v=v.slice(0,y));var b="";0!=g.length?b+="<li><a href='"+p+"' class='search-result-title'>"+T(i,g[0])+"</a>":b+="<li><a href='"+p+"' class='search-result-title'>"+i+"</a>",v.forEach((function(t){b+="<a href='"+p+'\'><p class="search-result">'+T(l,t)+"...</p></a>"})),b+="</li>",o.push({item:b,searchTextCount:a,hitCount:s,id:o.length})}})),1===e.length&&""===e[0])s.innerHTML='<div id="no-result"><i class="fa fa-search fa-5x" /></div>';else if(0===o.length)s.innerHTML='<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>';else{o.sort((function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hitCount!==e.hitCount?e.hitCount-t.hitCount:e.id-t.id}));var a='<ul class="search-result-list">';o.forEach((function(t){a+=t.item})),a+="</ul>",s.innerHTML=a}};r.addEventListener("input",a),$(".local-search-pop-overlay").remove(),$("body").css("overflow",""),proceedsearch()}})};$(".popup-trigger").click((function(t){t.stopPropagation(),!1===isfetched?searchFunc(path,"local-search-input","local-search-result"):proceedsearch()})),$(".popup-btn-close").click(onPopupClose),$(".popup").click((function(t){t.stopPropagation()})),$(document).on("keyup",(function(t){27===t.which&&$(".search-popup").is(":visible")&&onPopupClose()}))</script><script>"serviceWorker"in navigator&&window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js")})</script><script src="/blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/blog/live2dw/assets/Epsilon2.1.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":true},"react":{"opacity":1},"log":false});</script></body></html>