<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## (一).前言: 前面我們已經對于AndroidAnnotations框架的事件綁定做了講解,今天我們開始具體學習一下線程處理(Threading)方法。 FastDev4Android框架項目地址:[https://github.com/jiangqqlmj/FastDev4Android](https://github.com/jiangqqlmj/FastDev4Android)? 已更新如下: ![](https://box.kancloud.cn/2016-01-18_569c8eb29a4ea.jpg) 自AndroidAnnotation1.0起,讓我們從今天開始擺脫AsyncTask吧 ## (二).@Background 使用@Background注解的方法可以運行在子線程中而非UI線程。使用實例如下: ~~~ void myMethod() { someBackgroundWork("hello", 42); } @Background voidsomeBackgroundWork(String aParam, long anotherParam) { [...] } ~~~ 該方法可以在單獨的線程上面運行,但不意味著開啟一個新線程。因為這邊注解的內部使用一個共享的線程池,這樣可以避免創建更多的線程。這意味著兩個都使用@Background注解的方法可以并行的運行。 ## (三).@Id 自AndroidAnnotations3.0 如果你想要取消一個后臺任務,你可以使用id字段,每一個任務都可以通過BackgroundExecutor.cancelAll("id") ~~~ void myMethod() { someCancellableBackground("hello", 42); [...] boolean mayInterruptIfRunning = true; BackgroundExecutor.cancelAll("cancellable_task",mayInterruptIfRunning); } @Background(id="cancellable_task") voidsomeCancellableBackground(String aParam, long anotherParam) { [...] } ~~~ ## (四).@Serial 自AndroidAnnotations3.0起,默認情況下,使用@Background注解的方法是并行運行的。如果你想要這些任務方法按照順序執行,你可以使用@Serial注解字段,所有后臺的任務將會按照順序執行。使用實例如下: ~~~ void myMethod() { for (int i = 0; i < 10; i++) someSequentialBackgroundMethod(i); } @Background(serial ="test") voidsomeSequentialBackgroundMethod(int i) { SystemClock.sleep(newRandom().nextInt(2000)+1000); Log.d("AA", "value : "+ i); } ~~~ ## (五).@Delay 自AndroidAnnotations3.0起,如果想要讓后臺方法延遲運行,你可以使用@Delay參數 ~~~ @Background(delay=2000) voiddoInBackgroundAfterTwoSeconds() { } ~~~ ## (六).@UiThread 使用@UiThread注解的方法可以在UIThread進行運行,使用實例如下: ~~~ void myMethod() { doInUiThread("hello", 42); } @UiThread voiddoInUiThread(String aParam, long anotherParam) { [...] } ~~~ 就不在使用AsyncTask ## (七).@SupposeBackground 自AndroidAnnotations3.1起,使用實例: ~~~ @EBean public class MyBean{ @SupposeBackground voidsomeMethodThatShouldNotBeCalledFromUiThread() { //if this method will be called from theUI-thread an exception will be thrown } @SupposeBackground(serial ={"serial1", "serial2"}) voidsomeMethodThatShouldBeCalledFromSerial1OrSerial2() { //if this method will be called from anotherthread then a background thread with a //serial "serial1" or"serial2", an exception will be thrown } } ~~~ ## (八).@SupposeUiThread 確保方法在UiThread中運行,使用實例: ~~~ @EBean public class MyBean{ @SupposeUiThread voidsomeMethodThatShouldBeCalledOnlyFromUiThread() { //if this method will be called from abackground thread an exception will be thrown } } ~~~ 到此位置關于AndroidAnnotations注解線程處理(Threading)使用方法已經全部講解完成了。 FastDev4Android項目已經添加配置了AndroidAnnotations框架,后期的框架項目中也會主要使用這個DI框架,.歡迎大家去Github站點進行clone或者下載瀏覽. [https://github.com/jiangqqlmj/FastDev4Android](https://github.com/jiangqqlmj/FastDev4Android)? 同時歡迎大家star和fork整個開源快速開發框架項目~如果有什么意見和反饋,歡迎留言,必定第一時間回復。也歡迎有同樣興趣的童鞋加入到該項目中來,一起維護該項目。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看