Android App Master Service

Source: Internet
Author: User


Packagecom.app.biqoo.logic;Importjava.util.ArrayList;Importjava.util.LinkedList;ImportJava.util.Queue;Importandroid.app.Activity;ImportAndroid.app.Service;Importandroid.content.Intent;ImportAndroid.os.Handler;ImportAndroid.os.IBinder;ImportAndroid.os.Message;ImportCom.app.biqoo.bean.Task;Importcom.app.biqoo.ui.IBiqooActivity;

Public classMainserviceextendsServiceImplementsRunnable {//Task Queue Private StaticQueue<task> tasks=NewLinkedlist<task>(); Private StaticArraylist<activity> appactivities =NewArraylist<activity>(); //whether to run the county Private BooleanIsrun; Handler Handler=NewHandler () { Public voidhandlemessage (android.os.Message msg) {Switch(msg.what) { CaseTask.welcome://Home Pageibiqooactivity Activity= (ibiqooactivity) getactivitybyname ("Welcomeactivity"); Activity.refresh (); Break; default : Break; } } }; /** Get activity objects based on activity's name*/ PrivateActivity getactivitybyname (String name) {if(!Appactivities.isempty ()) { for(Activity activity:appactivities) {if(NULL!=activity) { if(Activity.getclass (). GetName (). IndexOf (name) >0){ returnactivity; } } } } return NULL; } /** Add an Activity object*/ Public Static voidaddactivity (activity activity) {Appactivities.add (activity); } /** Add task to Task queue*/ Public Static voidNewTask (Task t) {Tasks.add (t); } @Override Public voidonCreate () {//TODO Auto-generated method stubsisrun=true; Thread Thread=NewThread ( This); Thread.Start (); Super. OnCreate (); } @Override Public voidrun () {//TODO Auto-generated method stubs while(isrun) {Task Task=NULL; if(!Tasks.isempty ()) {Task=tasks.poll ();//Remove the task from the queue after performing the task if(NULL!=Task) {dotask (Task); } } Try{Thread.Sleep (1000); } Catch(Exception e) {//TODO Auto-generated catch blockE.printstacktrace (); } } } //Processing Tasks Private voiddotask (Task t) {Message msg=Handler.obtainmessage (); Msg.what=T.gettaskid (); Switch(T.gettaskid ()) { CaseTask.WELCOME:System.out.println ("Dotask>>>>> Welcome"); Msg.obj= "Home"; Break; default : Break; } handler.sendmessage (msg); } @Override Publicibinder onbind (Intent Intent) {//TODO Auto-generated method stubs return NULL; }} PackageCom.app.biqoo.bean;ImportJava.util.Map; Public classTask {//task ID Private inttaskId; Public Static Final intWELCOME = 0; //Parameters PrivateMap<string,object>Taskparams; PublicTask () {Super(); } PublicTask (intTaskId, Map<string, object>taskparams) { Super(); This. TaskId =taskId; This. Taskparams =Taskparams; } Public intGetTaskID () {returntaskId; } Public voidSettaskid (inttaskId) { This. TaskId =taskId; } PublicMap<string, object>Gettaskparams () {returnTaskparams; } Public voidSettaskparams (map<string, object>taskparams) { This. Taskparams =Taskparams; } } PackageCom.app.biqoo.ui; Public Interfaceibiqooactivity {/** Initialize Data*/ voidinit (); /** * Refresh UI*/ voidRefresh (); }

Android App Master Service

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.