Thursday, June 10, 2010

[android-developers] Handling events from one service for multiple activities

I have a class A which extends TabActivity and creates Activities B, C
and D as tabs in its onCreate() function. Also, class A initializes
another service handler class S which is responsible for establishing
a connection to a service and implementing callback handlers for the
service. Any of the Activities B, C and D should be able to receive
events from the service and update accordingly. If I receive any event
in class S from the the service then I want to call a function in
Activity B which would be responsible to update the UI elements in
Activity B based on the event received. You can assume that the user
is in Activity B when the event arrives.

Can I call an activity function like the following in the stub handler
for the callback in my class S -

private Callback mEventListener = new OperationCallback.Stub()
{
@Override
public void handleOperationEvent(Payload payload)

{
B objB = new B(); // Is this valid? Since B is an activity.
B.postEventToHandler(payload); // postEventToHandler() is a
method inside B

}
};


Let me know I am doing the right thing to achieve what I want. Also,
let me know if you need more clarification.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment