Android Context 是一个抽象基类,它提供了许多应用程序相关的功能。以下是 Context 可以执行的一些操作:
Context.getSystemService(Class<T> service)Context.registerReceiver(BroadcastReceiver receiver, IntentFilter filter)Context.sendBroadcast(Intent intent)Context.getContentResolver().registerContentObserver(Uri uri, boolean notifyForDescendents, String selection, String[] selectionArgs)Context.getResources().getString(R.string.example_string)Context.getTheme()Context.getPackageName()Context.getResources().getIdentifier(String name, String type, String package)Context.startActivity(Intent intent)Context.startService(Intent intent)Context.bindService(Intent intent, ServiceConnection conn, int flags)Context.unbindService(ServiceConnection conn)Context.showDialog(int id, Dialog dialog)Context.getFilesDir() 或 Context.getCacheDir()Context.getContentResolver().registerContentProvider(String authority, ProviderInfo info)Context.registerComponentCallbacks(ComponentCallbacks callback)Context.getPackageManager().getApplicationInfo(String packageName, int flags)这些操作只是 Context 提供的部分功能,还有其他一些操作可以根据需要进行使用。在实际开发中,我们通常使用 Activity 或 Application 等类来执行这些操作,而不是直接使用 Context。