java - Considerations when adding a service to an existing android project? -


i new android programming , pretty proficient in java, have never done threading in java.

the project working on inherited programmer (who no longer works @ company). code received not amazing (2 giant classes, each 1500+ lines). have spent better part of month reorganizing, cleaning etc.

i looking add service or background-thread because how should have been organized in first place. being android novice read through dev docs, looked @ examples , various tutorials. considerations should take account , how should decide better project?

edit:

the service looking implement needs monitor information coming in on usb input "asking" device software version, example. if user starts activity usbmanager stopped. not ideal information have been missed when first activity paused. if going use service best way communicate it?

first of all, please keep in mind 'giant god' classes not atrocious in android.

since there's no way identify service talking about, think need better understanding on whether should service or asynctask run.

service

a service part of application has no ui. may called ui(activity) started, or may started other component of application. when developing, have freedom place on different thread, or run in different task or process. allows separate ui. additionally, may start service run independently (startservice) or bind activity (bindservice) depending upon needs. using custom handlers, can set callbacks update ui progress. service not end if user changes activities, may ended @ time os. [1]

asynctask

a asynctask instantiated ui thread. allows specific callbacks, simplifies process of multi-threading purposes of relatively short transactions (as compared dedicated separate threaded services) inherently tied actions performed activity. whenever user changes activities, asynctask put on "pause" , may die because there no ui thread activity longer. [2]

thus, handle situations won't have use neither.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -