A brief introduction to the code specification for androidannotations in development: (MVC thinking) time is too tight, put the code first:
Activity's Code:
Package Edu.njupt.zhb.main;import Org.androidannotations.annotations.afterviews;import Org.androidannotations.annotations.bean;import Org.androidannotations.annotations.eactivity;import android.app.activity;/** * @author Zheng Haibo * @web http://www.mobctrl.net */@EActivity (R.layout.main) public Class Mainactivity extends Activity {@BeanMainActions mainactions; @AfterViewsvoid afterviews () {dosomething ();} private void DoSomething () {Mainactions.doactionsinthread (+, new Uicallback () {@Overridepublic void Onbackgroundend () {//TODO auto-generated method stub//Write the CodeSystem.out.println ("The background thread end ...");}});}
Business logic Mainactions
Package Edu.njupt.zhb.main;import Org.androidannotations.annotations.background;import Org.androidannotations.annotations.ebean;import Org.androidannotations.annotations.rootcontext;import Org.androidannotations.annotations.uithread;import android.content.context;import android.widget.Toast;/** * @ Author Zheng haibo * @web http://www.mobctrl.net */@EBeanpublic class Mainactions {@RootContextContext context; @Backgrou ndvoid doactionsinthread (int params, uicallback uicallback) {//database,net,file,sp ... int result = 0;for (int i = 0; I & Lt Params i++) {result = result + I;try {thread.sleep ()} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.pri Ntstacktrace ();} SYSTEM.OUT.PRINTLN ("Test the thread is run in the background ..."); Runinuithread (result, uicallback);} @UiThreadvoid runinuithread (int result, Uicallback uicallback) {toast.maketext (context, result + ", just a test", Toast.le Ngth_short). Show (); System.out.println ("You can write the UI code ..."); Uicallback.onBackgroundend ();}}
Callback Interface
Package edu.njupt.zhb.main;/** * @author Zheng Haibo * @web http://www.mobctrl.net */public interface Uicallback {public V OID Onbackgroundend ();//...}
I think it's written in this way. The code will be more refreshing.
Maybe say the reason, go back to the dormitory first.
。。。
Androidannotations of background and Uithread in conjunction with the use of the test