Android : Several activities sharing common code
<p>I have an Android application composed by several Activities.  Most of them need to check whether an active network is available or not:</p>

<pre><code>public boolean isNetworkAvailable() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    ...
}
</code></pre>

<p>I would like to move that code to a helper class in order to avoid the need to write that code in every Activity, but calls to <code>getSystemService</code> are only allowed from an Activity.</p>

<p>The other alternative is to move that code to a parent activity use inheritance but:</p>

<ol>
<li>Every activity already extends from android.app.Activity</li>
<li>Some of my activities already extend from a common my.package.BaseActivity (Activity &lt;- BaseActivity &lt;- XXXActivity)</li>
</ol>

<p>so I don't like this idea very much.</p>

<p>What do you recommend in this case?  Is there any other alternative?</p>
