문제

I am developing an android app which does a long running task either invoked by user or scheduled by Alarm.

I have designed it in Activity - > Service - > AsyncTask form of invocation.

I use the Otto library to bring UI updates directly from the AsyncTask to the activity.

I have two question:
1 Is there a reason I should use Otto to do the communication from AsyncTask - > Service and then from Service - > Activity. I have seen lots of apps use this pattern.

2 When should I run the service in foreground ? The argument of not being killed by low memory can be abused. I want to make a conscious decision. I believe it should run in foreground when invoked by user manually and not when kicked by Alarm.

도움이 되었습니까?

해결책

I use the Otto library to bring UI updates directly from the AsyncTask to the activity.

Note that event buses may or may not, deliver events in sequence (pre/post). Besides, with Otto, you can post events on main threads from another thread. So a simple runnable can replace AsyncTask.

1 Is there a reason I should use Otto to do the communication from AsyncTask - > Service and then from Service - > Activity. I have seen lots of apps use this pattern.

Some Client --> Service -- > Executor queue --> Model/data changes --> Broadcast Otto events --> Interested clients update their views from model/data.

2 When should I run the service in foreground ? The argument of not being killed by low memory can be abused. I want to make a conscious decision. I believe it should run in foreground when invoked by user manually and not when kicked by Alarm.

Service should be able to survive re-starts. At boot It checks for an pending tasks in queue and resumes them. It should shut down when no pending tasks. it should start when a new task is posted.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top