22
33import android .os .Bundle ;
44
5+ import com .queue .library .Dispatch ;
6+ import com .queue .library .DispatchThread ;
7+
58import androidx .appcompat .app .AppCompatActivity ;
69
710public class MainActivity extends AppCompatActivity {
@@ -10,5 +13,75 @@ public class MainActivity extends AppCompatActivity {
1013 protected void onCreate (Bundle savedInstanceState ) {
1114 super .onCreate (savedInstanceState );
1215 setContentView (R .layout .activity_main );
16+
17+
18+ // /**
19+ // * use a
20+ // */
21+ // final StringBuffer output = new StringBuffer();
22+ // AsyncTask.execute(() -> {
23+ // output.append(1).append("-").append(Thread.currentThread().getName()).append(", ");
24+ // GlobalQueue.getMainQueue().postRunnableBlocking(() -> {
25+ // // do you work , in the main-Thread
26+ // output.append(2).append("-").append(Thread.currentThread().getName()).append(", ");
27+ //
28+ // });
29+ // output.append(3).append("-").append(Thread.currentThread().getName()).append(", ");
30+ //
31+ // // invoke in the main-Thread and return a string data
32+ // String message = GlobalQueue.getMainQueue().call(() -> {
33+ // output.append(4).append("-").append(Thread.currentThread().getName()).append(", ");
34+ // return "hello world";
35+ // });
36+ // output.append(5).append("-").append(Thread.currentThread().getName()).append(" data ").append(message);
37+ // System.out.println(output.toString());
38+ // // output the order "1 2 3 4"
39+ // });
40+
41+ // final StringBuffer output = new StringBuffer();
42+ // AsyncTask.execute(() -> {
43+ // output.append(1).append(", ");
44+ // GlobalQueue.getMainQueue().postRunnableBlocking(() -> {
45+ // // do you work , in the main-Thread
46+ // output.append(2).append(", ");
47+ //
48+ // });
49+ // output.append(3).append(", ");
50+ //
51+ // // invoke in the main-Thread and return a string data
52+ // String message = GlobalQueue.getMainQueue().call(() -> {
53+ // output.append(4).append(", ");
54+ // return "hello world";
55+ // });
56+ // output.append(5).append(" data ").append(message);
57+ // System.out.println(output.toString());
58+ // // output the order "1 2 3 4"
59+ // });
60+
61+ /**
62+ * use b
63+ */
64+ Dispatch messageDispatch = DispatchThread .create ("message" );
65+
66+ messageDispatch .postRunnable (() -> {
67+ // do you work , work in message thread
68+ });
69+
70+ System .out .println ("1" );
71+ messageDispatch .postRunnableScissors (() -> {
72+ System .out .println ("2" );
73+ });
74+ System .out .println ("3" );
75+ // output 1 2 3
76+
77+ // from message thread get a number, it will blocking until working finish.
78+ int i = messageDispatch .call (() -> 1 );
79+
80+
81+ messageDispatch .postRunnableInIdleRunning (() -> {
82+ // do your work , when the message thread idle will callback this runable
83+ });
1384 }
85+
86+
1487}
0 commit comments