Hekki wrote:
> Simple was a shortcut for "Should be a really easy task to achieve by
> developers on a platform designed around the 'always connected' idea".
> And the four lines of code you need to do it are easy enough, I admit,
> but i can still not see why I need to have a context to ask the OS if
> it is connected to the internet.
ConnectivityManager -- as is just about everything accessed via
getSystemService() -- is actually a wrapper around a client-side proxy
to a remote AIDL service, based on my reading of the source code.
Presumably, that's because the *real* "ConnectivityManager" is actually
a system daemon, one that handles all of the failover and such between
multiple connectivity methods (3G, WiFi, etc.). Applications need to use
IPC -- in this case, AIDL -- to communicate with that system process to
figure out if we are indeed connected, and by what means.
Using AIDL outside of system services requires a Context, for the
bindService() call. I am having difficulty with Google Code Search
tracking down the actual implementation of getSystemService() ("you are
in a maze of twisty little Context implementations, all not quite
alike"). However, I would guess there is something akin to bindService()
going on there as well.
*That's* the reason I said it wasn't "simple". What looks on the surface
like a trivial question is not nearly so trivial.
With respect to the reusability issue, I try to avoid holding onto
Context objects where possible, requiring them as parameters to methods
where and when I need them. That doesn't always work, and it adds extra
tedium to the reuse...but if you never hold onto the Context, you can
never leak it.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
Android App Developer Books: http://commonsware.com/books
--
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