> I have an activity that uses a service. While the service is running (it
> sends
> some stuff in background) I display a progress bar and disable the send
> button.
>
> Now I created an Intent to update the interface after the send service has
> finished. How can I do this only if the activity is still on top? I tried
> to
> figure out this in the service with:
>
> ActivityManager.RunningTaskInfo actManager = new
> ActivityManager.RunningTaskInfo();
> ComponentName topAct = actManager.topActivity;
> String name = topAct.getPackageName();
>
> But this gives me a null pointer on last line...
>
>
> What could I do?

If the service is a local service (in the same application as the
activity), then do not use an Intent. Have the activity register a
callback or listener object with the service, and have the service call
that object as needed to inform the activity of progress.

Regardless of whether the service is local or remote (i.e., using AIDL),
the decision to display things should be made by the activity, not the
service. The service should always say "I am done"; the activity can
decide what to do or not to do with this information.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



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

Reply via email to