Android复习(一)基础知识

1. 现在可以使用 Kotlin、Java 和 C++ 语言编写 Android 应用

2.Android四大组件依然坚挺,这是基础并且没有改变的迹象

Activity  服务  广播接收器  内容提供程序

2.1 Service ,Google也意识到存在的灵活性问题,但是由于使用广泛,所以并不打算改变

     目前使用服务的应用类型:音乐、动态壁纸、通知侦听器、屏幕保护程序、输入方法、无障碍功能服务等

2.2 广播接收器

    广播接收器更常见的用途只是作为通向其他组件的通道,旨在执行极少量的工作。例如,它可能会根据带 JobScheduler 的事件调度 JobService 来执行某项工作

     广播接收器作为 BroadcastReceiver 的子类实现,并且每条广播都作为 Intent 对象进行传递

JobScheduler
Note: Beginning with API 30 (Build.VERSION_CODES.R), JobScheduler will throttle runaway applications. Calling schedule(android.app.job.JobInfo) and other such methods with very high frequency is indicative of an app bug and so, to make sure the system doesn't get overwhelmed, JobScheduler will begin to throttle apps that show buggy behavior, regardless of target SDK version.

2.3 内容提供者

  对系统而言,内容提供程序是应用的入口点,用于发布由 URI 架构识别的已命名数据项

3.对于组件的启动方式

    Service在 Android 5.0(API 级别 21)及更高版本中,可以使用JobScheduler 来调度,当然低版本中依然使用startService或bingService的方式操作 

注意:如果您使用 Intent 来启动 Service,请使用显式 Intent 来确保应用的安全性。使用隐式 Intent 启动服务存在安全隐患,因为您无法确定哪些服务将响应 Intent,且用户无法看到哪些服务已启动。从 Android 5.0(API 级别 21)开始,如果使用隐式 Intent 调用 bindService(),系统会抛出异常。请勿为您的服务声明 Intent 过滤器。

4.版本兼容问题

  如果应用包含某个功能或者设备的调用,可以在清单中进行配置

  

<manifest ... >
    <uses-feature android:name="android.hardware.camera.any"
                  android:required="true" />
    <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="19" />
    ...
</manifest>

  通过示例中所述的声明,没有相机且 Android 版本低于 2.1 的设备将无法从 Google Play 安装您的应用。不过,您可以声明您的应用使用相机,但并不要求必须使用。在此情况下,您的应用必须将 required 属性设置为 false,并在运行时检查设备是否拥有相机,然后根据需要停用任何相机功能

参考文章:官方文档: https://developer.android.google.cn/guide/components/fundamentals

原文地址:https://www.cnblogs.com/developer-wang/p/12618623.html