学习资料:Build Your First Android App in Java。
通过 Android Studio 的 File->New Project 创建一个 Basic Activity,选择 Java 或者 Kotlin 语言,选择最小的 sdk 版本。
项目目录说明:源代码核心目录是 app/src/main,在 Android Studio 的左侧面板中看到目录树的根是 app/src/main。
➜ 01-first-proj git:(main) ✗ ls app/src/main
AndroidManifest.xml java res
manifests/AndroidManifest.xml 是对 app 内各组件的描述,android runtime 读取该文件。
java 目录中是 app 的源代码。
res 目录中是 app 使用的资源文件,其中:
通过 Android Studio 的 Tools -> AVD Manager 安装本地安卓模拟器,然后就可以用运行按钮启动:
进入 android 手机的开发者设置,打开 USB 调试,将手机脸上电脑上,在 Android Studio 中就可以看到增加的设备,选择并运行即可。
App component 加载顺序是不确定的,而且可能会被随时销毁,不能在 app component 中存放数据。
it’s possible for your app components to be launched individually and out-of-order, and the operating system or user can destroy them at any time. Because these events aren’t under your control, you shouldn’t store or keep in memory any application data or state in your app components, and your app components shouldn’t depend on each other.