Androidを学んでいるので、ちょっと覗いてAndroidスタジオの新しいキーボードショートカットを学んでいました。私はgetSystemService(string)
方法で迅速な定義の検索を行なったし、それがこれをプルアップ:getSystemService(文字列)メソッドがアクティビティクラスのスタブであるのはなぜですか?
は何とか隠されたこのメソッドのソースですか?本当にちょうどRuntimeException
を投げることはできません。
Androidを学んでいるので、ちょっと覗いてAndroidスタジオの新しいキーボードショートカットを学んでいました。私はgetSystemService(string)
方法で迅速な定義の検索を行なったし、それがこれをプルアップ:getSystemService(文字列)メソッドがアクティビティクラスのスタブであるのはなぜですか?
は何とか隠されたこのメソッドのソースですか?本当にちょうどRuntimeException
を投げることはできません。
これはスタブではありませんが、ソースが隠されているため、実際にこのメソッドを呼び出すと、その証拠が表示され、望ましく機能します。
また、Android Framework
の一部であるさまざまなクラスのメソッドが多数ありますが、フレームワークを扱う実際のロジックは公開されていません。
ありがとう、ありがとう。オンラインで見つけることができるときに、ここにソースを隠している理由はありますか? – intA
実際にgetSystemService
の内容を確認したい場合は、GithubのAndroidソースコードをご覧ください。
これは継承ツリーです。
Activity - >ContextThemeWrapper - Context.java
インサイド>Context
あなたはそれが実際に何をするかを見つけることができます。
/**
* Return the handle to a system-level service by class.
* <p>
* Currently available classes are:
* {@link android.view.WindowManager}, {@link android.view.LayoutInflater},
* {@link android.app.ActivityManager}, {@link android.os.PowerManager},
* {@link android.app.AlarmManager}, {@link android.app.NotificationManager},
* {@link android.app.KeyguardManager}, {@link android.location.LocationManager},
* {@link android.app.SearchManager}, {@link android.os.Vibrator},
* {@link android.net.ConnectivityManager},
* {@link android.net.wifi.WifiManager},
* {@link android.media.AudioManager}, {@link android.media.MediaRouter},
* {@link android.telephony.TelephonyManager}, {@link android.telephony.SubscriptionManager},
* {@link android.view.inputmethod.InputMethodManager},
* {@link android.app.UiModeManager}, {@link android.app.DownloadManager},
* {@link android.os.BatteryManager}, {@link android.app.job.JobScheduler},
* {@link android.app.usage.NetworkStatsManager}.
* </p><p>
* Note: System services obtained via this API may be closely associated with
* the Context in which they are obtained from. In general, do not share the
* service objects between various different contexts (Activities, Applications,
* Services, Providers, etc.)
* </p>
*
* @param serviceClass The class of the desired service.
* @return The service or null if the class is not a supported system service.
*/
@SuppressWarnings("unchecked")
public final <T> T getSystemService(Class<T> serviceClass) {
// Because subclasses may override getSystemService(String) we cannot
// perform a lookup by class alone. We must first map the class to its
// service name then invoke the string-based method.
String serviceName = getSystemServiceName(serviceClass);
return serviceName != null ? (T)getSystemService(serviceName) : null;
}
クール、ありがとう。私は実際には、Activityクラスのソースコード[ここ](https://android.googlesource.com/platform/frameworks/base/+/android-2.3.5_r1/core/java/android/app/Activity.java)を見ていました。 )アクティビティの実装がContext(アクティビティがコンテキストから継承することを認識している)とは異なるように見えます。 – intA
SDKマネージャにダウンロードしたソースがありますか? –
APIレベル23と24のSDKをダウンロードしました。それが私に本当の情報源を示していないのはなぜですか? API 21を探しているからですか? – intA
あなたはSDKを持っているかもしれませんが、ソースとドキュメンテーションは含まれていません –