Androidannotations background and Uithread with reference to use

Source: Internet
Author: User

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

Related Article

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.