Bored to write an android Gcdのdispatch_async

Source: Internet
Author: User

Block

public interface block{/** * * Required Tasks * * @return The result of Object execution */void ibuild ();}


GCD

/** * gcd of android *  *  @author  fred don * */ Public class gcd{public static string dispatch_get_main_queue () {return  "main";} /** * 1 x background   Run  *  *  @author  fred don *  @param  threadName *            [main  UI thread run  ,others /background   run] *  @param  block */public static void  Dispatch_async (String threadname, final block block) {if  ("Main". Equals (ThreadName)) { Handler.post (New runnable () {@Overridepublic  void run () {if  (block != null) {block. Ibuild ();}});} Else{thread t = new thread (New runnable () {@Overridepublic  void run () {if   (block != null) {block. Ibuild ();}}); T.setname (ThreadName); T.start ();}}  static handler handler=new handler ();} 


Usage

Background thread Gcd.dispatch_async ("Back", new Block () {@Overridepublic void Ibuild () {println (Thread.CurrentThread (). GetName ( )); Gcd.dispatch_async ("main", new Block () {@Overridepublic void Ibuild () {println (Thread.CurrentThread (). GetName ());});}); /ui thread Gcd.dispatch_async ("main", new Block () {@Overridepublic void Ibuild () {println (Thread.CurrentThread (). GetName () );}}); public static void println (String s) {log.i ("Gcdtester", s);}


Bored to write an android Gcdのdispatch_async

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.