"fourth article" Androideventbus Source code reading and analysis

Source: Internet
Author: User
<span id="Label3"></p><p><p><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">1, analyze Androideventbus's Registered source Code:</span></p></p><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">our first step in using Androideventbus is to register Eventbus with the following code:</span></span> <ol class="linenums" style="padding-left: 0px;"> <ol class="linenums" style="padding-left: 0px;"> <li class="L0" style="list-style-type: none; padding-left: 0px;"><pre>Eventbus.getdefault (). Register (<span style="color: #0000ff;"></span>this);</pre><p></p></li> </ol> </ol><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">first, The Eventbus object is obtained, and the object is obtained using simple interest mode:</span></span><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">Eventbus.java inside</span></span> <ol class="linenums" style="padding-left: 0px;"> <li class="L0" style="list-style-type: none; padding-left: 0px;"><code class="language-java"><code class="language-java"><code class="language-java"></code></code></code><pre><pre><span style="color: #0000ff;"></span> public <span style="color: #0000ff;">Static</span> <span style="color: #000000;">eventbus getdefault () { </span><span style="color: #0000ff;">if</span><span style="color: #0000ff;">null</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">synchronized</span> (eventbus. <span style="color: #0000ff;"> Class</span><span style="color: #000000;"> )</span>{<span style="color: #0000ff;">if</span><span style="color: #0000ff;">null</span><span style="color: #000000;">) { </span><span style="color: #0000ff;">new</span> <span style="color: #000000;"> Eventbus (); } } } </span> <span style="color: #0000ff;">return</span> <span style="color: #000000;">sdefaultbus; }</span></pre></pre><code class="language-java"><code class="language-java"><code class="language-java"></code></code></code><p><p></p></p><code class="language-java"><code class="language-java"><span class="kwd"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><br></span></span></code></code></li> </ol><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">then it is:</span></span> <ol class="linenums" style="padding-left: 0px;"> <li class="L0" style="list-style-type: none; padding-left: 0px;"><code class="language-java"><code class="language-java"><code class="language-java"></code></code></code><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">Register (Object subscriber) {</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(subscriber = =<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">synchronized</span></span>(<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #000000;"><span style="color: #000000;">mmethodhunter.findsubcribemethods (subscriber);</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span>}</pre><code class="language-java"><code class="language-java"><code class="language-java"></code></code></code><p><p></p></p><code class="language-java"><code class="language-java"><span class="kwd"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><br></span></span></code></code></li> </ol><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">track to</span></span><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">Mmethodhunter</span></span></span><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">.</span></span></span><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">Findsubcribemethods</span></span></span><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">(</span></span></span><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">Subscriber</span></span></span><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">); Keep Looking down:</span></span></span><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pun" style="font-family:consolas, ' liberation Mono ', Menlo, Courier, monospace; font-size:12.941176414489746px; line-height:17.996322631835938px; white-space:pre; Background-color: #f7f7f9; "><span style="color: #48484c; font-size:16.47058868408203px;"><span style="font-size:12pt;" data-wiz-span=" Data-wiz-span ">mmethodhunter Register at Code header: </span> </span> <br> </span></span> <ol class="linenums" style="padding-left: 0px;"> <ol class="linenums" style="padding-left: 0px;"> <li class="L0" style="list-style-type: none; padding-left: 0px;"><pre><span style="color: #008080;">1</span> <span style="color: #008000;">/**</span> <span style="color: #008080;">2</span> <span style="color: #008000;">* The Subscriber method hunter, find all of the Subscriber ' s methods</span> <span style="color: #008080;">3</span> <span style="color: #008000;">* Annotated with @Subcriber</span> <span style="color: #008080;">4</span> <span style="color: #008000;">*/</span> <span style="color: #008080;">5</span> subscibermethodhunter mmethodhunter =newsubscibermethodhunter (msubcribermap);</pre><p></p></li> </ol> </ol><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">used to find all annotation methods that use @subcriber</span></span><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">and then we follow</span></span><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">Findsubcribemethods</span></span></span><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">(</span></span></span><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pln" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">Subscriber</span></span></span><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">) Look inside:</span></span></span><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span class="pun" style="font-family: Consolas, ‘Liberation Mono‘, Menlo, Courier, monospace; font-size: 12.941176414489746px; line-height: 17.996322631835938px; white-space: pre; background-color: #f7f7f9;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="color: #000000;">Traverse</span></span></span></span> <ol class="linenums" style="padding-left: 0px;"> <li class="L0" style="list-style-type: none; padding-left: 0px;"><code class="language-java"><code class="language-java"><code class="language-java"></code></code></code><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> public</span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">findsubcribemethods (Object Subscriber) {</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(msubcribermap = =<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">Throw</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span>NullPointerException ("the Msubcribermap is Null.")<span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>Class<?> Clazz =<span style="color: #000000;"><span style="color: #000000;">Subscriber.getclass ();</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">find the registration method that meets the requirements in the class until the object class</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> while</span>(clazz! =<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>&&!<span style="color: #000000;"><span style="color: #000000;">ISSYSTEMCALSS (clazz.getname ())) {</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">Final</span></span>method[] Allmethods =<span style="color: #000000;"><span style="color: #000000;">clazz.getdeclaredmethods ();</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>(<span style="color: #0000ff;"><span style="color: #0000ff;">int</span></span>i = 0; I < allmethods.length; i++<span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span>Method method =<span style="color: #000000;"><span style="color: #000000;">allmethods[i];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">parsing functions according to annotations</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span>subscriber annotation = Method.getannotation (subscriber.<span style="color: #0000ff;"><span style="color: #0000ff;">class</span></span><span style="color: #000000;"><span style="color: #000000;">);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(annotation! =<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Get method Parameters</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span>class<?>[] Paramstypeclass =<span style="color: #000000;"><span style="color: #000000;">method.getparametertypes ();</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">the <span style="color: #008000;">Subscription function supports only one parameter</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(paramstypeclass! =<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span>&& Paramstypeclass.length = = 1<span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>class<?> Paramtype = Converttype (paramstypeclass[0<span style="color: #000000;"><span style="color: #000000;">]);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span>EventType EventType =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">eventtype (paramtype, Annotation.tag ());</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>Targetmethod Subscribemethod =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Targetmethod (method, eventtype,</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #000000;"><span style="color: #000000;">Annotation.mode ());</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #000000;"><span style="color: #000000;">subscibe (eventtype, subscribemethod, subscriber);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> at</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>}<span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">End</span> for</span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">gets the parent class to continue looking for methods that meet the requirements in the parent class</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>Clazz =<span style="color: #000000;"><span style="color: #000000;">Clazz.getsuperclass ();</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> in</span>}</pre><code class="language-java"><code class="language-java"><code class="language-java"></code></code></code><p><p></p></p><code class="language-java"><code class="language-java"><span class="kwd"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><br></span></span></code></code></li> </ol><span style="color: #000000;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">and then</span></span><span class="pln" style="font-size: 12.941176414489746px;"><span class="pln" style="font-size: 12.941176414489746px;"> <span style="font-size: 12pt;" data-wiz-span="data-wiz-span">subscibe</span> </span></span><span style="font-size: 12.941176414489746px;"><span style="font-size: 12.941176414489746px;"> <span class="pun"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">(</span></span><span class="pln"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">eventtype</span></span><span class="pun"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">,</span></span> <span class="pln"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"> subscribemethod</span></span><span class="pun"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">,</span></span> <span class="pln"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"> subscriber</span></span><span class="pun"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">); Code inside the method:</span></span> </span></span></span><span style="font-size: 12.941176414489746px;"><span style="font-size: 12.941176414489746px;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"><span style="color: #000000;">Msubcribermap is a map collection</span></span></span> .</span><strong style="color: #bebec5; font-size: 12.941176414489746px;"><strong style="color: #bebec5; font-size: 12.941176414489746px;"><span style="color: #ff0000;"><span class="pun"><br></span></span></strong></strong> <!--WizRtf2Html Charset=0 --><span style="font-size: 14pt; color: #cfbfad; font-family: ‘Consolas‘;"><span style="font-size: 14pt; color: #cfbfad; font-family: ‘Consolas‘;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span"> </span></span></span> <ol class="linenums" style="padding-left: 0px;"> <li class="L0" style="list-style-type: none; padding-left: 0px;"><code class="language-c"><code class="language-c"><code class="language-c"></code></code></code><pre><pre><span style="color: #008000;">/**</span> <span style="color: #008000;"> * The event bus 's Subscriber's map</span><span style="color: #008000;">*</span>/<span style="color: #000000;"> map</span><eventtype, Copyonwritearraylist<subscription>> msubcribermap;</pre></pre><code class="language-c"><code class="language-c"><code class="language-c"></code></code></code><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span> <span style="color: #008000;"><span style="color: #008000;">/**</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #008000;"><span style="color: #008000;">* According to EventType storage subscriber list, Here EventType is the event type, an event corresponding to 0 to many Subscribers.</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span> <span style="color: #008000;"><span style="color: #008000;"> * </span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008000;"><span style="color: #008000;"> * </span></span><span style="color: #808080;"><span style="color: #808080;">@param</span></span><span style="color: #008000;"><span style="color: #008000;">Event Events</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span> <span style="color: #008000;"><span style="color: #008000;"> * </span></span><span style="color: #808080;"><span style="color: #808080;">@param</span></span><span style="color: #008000;"><span style="color: #008000;">method Subscription Methods Object</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #008000;"><span style="color: #008000;"> * </span></span><span style="color: #808080;"><span style="color: #808080;">@param</span></span><span style="color: #008000;"><span style="color: #008000;">Subscriber subscribers</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span> <span style="color: #008000;"><span style="color: #008000;">*/</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">Private</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">subscibe (eventtype event, targetmethod method, Object subscriber) {</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span>Copyonwritearraylist<subscription> subscriptionlists =<span style="color: #000000;"><span style="color: #000000;">Msubcribermap.get (event);</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(subscriptionlists = =<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span>Subscriptionlists =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span>Copyonwritearraylist<subscription><span style="color: #000000;"><span style="color: #000000;">();</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>Subscription newsubscription =<span style="color: #0000ff;"><span style="color: #0000ff;">New</span></span><span style="color: #000000;"><span style="color: #000000;">Subscription (subscriber, method);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span><span style="color: #000000;"><span style="color: #000000;">(subscriptionlists.contains (NEWSUBSCRIPTION)) {</span></span><span style="color: #008080;"><span style="color: #008080;"></span> the</span> <span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;"> }</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #000000;"><span style="color: #000000;">Subscriptionlists.add (newsubscription);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Store Event Type key and subscriber information in map</span></span><span style="color: #008080;"><span style="color: #008080;"></span> +</span> <span style="color: #000000;"><span style="color: #000000;">msubcribermap.put (event, subscriptionlists);</span></span><span style="color: #008080;"><span style="color: #008080;"></span> -</span>}</pre><p><p></p></p></li> </ol> <span style="color: #000000;"><span style="color: #000000;"> <span style="font-size: 12pt;" data-wiz-span="data-wiz-span">Here you can see</span> that register is the way to <span style="font-size: 12pt;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">iterate through all the annotations</span></span> <span style="font-size: 12.941176414489746px;"><span style="font-size: 12pt;" data-wiz-span="data-wiz-span">@Subcriber and store the event type key and subscriber information in the MAP. This is similar to Eventbus code in the register, but Eventbus is</span></span> to <span style="font-family: Arial; font-size: 14px; line-height: 26px; widows: 1; background-color: #ffffff;">start with the OnEvent method to find, and Androideventbus is @subcriber to do traversal retrieval, but ultimately is </span> <span style="font-size: 12pt;">Store Event type key and subscriber information in MAP. </span></span></span><p><p>"fourth article" Androideventbus Source code reading and analysis</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.