Introduction to Androidannotations Code specification in development: (MVC thinking) time is too tight, put the code on 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 the code will be more refreshing in this way of thinking. Follow the reason, first back to the dorm ....
Androidannotations background and Uithread with reference to use