开发者

Activity synchronization

My application has one service and a set of activities.

Each activity covers a little task (such as ask the user to insert a number, or a text, or to express a preference).

The service starts the activities or a sub set of the activities.

The order in which the service starts the activities change开发者_如何学Gos with day hours.

But every time, the service has to wait the end of an activity (to obtain the activity result) before starts the next activity.

My idea was to use a wait() call in the service between two activities execution.

Each activity uses a sendBroadcast to return the result to a BroadcastReceiver.

The BroadcastReceiver executes the notify() to free the service and forwards the activity result to the service.

Obviously, this idea does not work. The problems are:

1) Starting many activities from a service gives me problem related to the Task each activities belongs to.

2) I don't know how to pass information from the BroadcastReceiver to the Service (in a first time I declared the BroadcastReceiver inside the Service class, but when the service entered the wait() the process remained blocked and BroadcastReceiver never receives).

Please, I accept all kind of suggestions. Maybe a change in the application architecture?

Thanks


The flow is typically one activity triggering the next. You should re-architect so that when you are ready to finish() activity1, you already know what Activity2 is and you start it from Activity1. Perhaps your service should expose a method that your activities can call to get a determination which should be the next activity. It is OK to do so as Services and Activities run in the same process and can call each other.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜