29.04.2011 0:01, Eric пишет:
The main thing I was asking about is, if the Service that the Activity needs is not created and/or connected yet, should the Activity handle that gracefully and watch out for NPE's, etc, or should the Activity just shut itself down in favor of a temporary "Please wait for data to load...."
Not sure why you connect NPEs vs. the service not being started yet or bound vs. the data not having been loaded yet.
You should always be able to start / bind to your own service, provided it's correctly implemented.
Activity, that then starts the original Activity back up again when the Service is finally ready. It sounds like all the advice so far is to write the Activity to work independent of Service availability, and don't bother with the temporary "Please wait..." Activity garbage.
I'd do this actually... informing the user in some way that the data is being loaded is useful in my opinion. At least you could show the spinning progress wheel.
The advantage of that approach would be that the main data-bearing Activity may then be written knowing the data it needs will always be at least available (i.e. non-null), albeit possibly out of date. But the advantage of the suggested approach is certainly that the Activity would be much more resilient if it can be displayed and interacted with, without the Service being available.
The service (the Android Service in your application) should always be available, in the sense that you can always start it as needed. It might not be able to connect to the "real" Service providing the data (meaning a Web Service, or what have you), may have no data or out of date data, but that's another matter entirely.
Taking the data storage and the data fetching parts for granted for a second, another piece that comes to my mind is some sort of notification mechanism.
You might already have something in your existing code base... If not - Android ContentProvider stuff is pretty useful for that, but building your own notification mechanism is not difficult either (or reusing Java Observable stuff) and can be more flexible.
I find it very useful (in my current project) to have the UI components register callbacks with my service, which the service then calls with various state change notifications. The dispatch is based on URIs.
-- Kostya Vasilyev -- http://kmansoft.wordpress.com -- 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

