アプリの最適化に関するベスト プラクティス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
以下では、品質を損なうことなくアプリを最適化するためのベスト プラクティスを紹介します。
ベースライン プロファイルを使用する
ベースライン プロファイルにより、コードの実行速度が初回起動から 30% 短縮され、すべてのユーザー操作(アプリの起動、画面間の移動、コンテンツのスクロールなど)が初回実行よりも滑らかになります。アプリの速度と応答性を高めると、1 日あたりのアクティブ ユーザー数が増加し、平均リピーター率が高まります。
起動プロファイルを使用する
起動プロファイルはベースライン プロファイルに似ていますが、DEX レイアウトを最適化してアプリの起動を高速化するために、コンパイル時に実行されます。
App Startup ライブラリを使用する
App Startup ライブラリを使用すると、初期化の必要があるコンポーネントごとに個別のコンテンツ プロバイダを定義する代わりに、単一のコンテンツ プロバイダを共有するコンポーネント初期化子を定義できます。これにより、アプリの起動時間が大幅に短縮されます。
ライブラリを遅延読み込みする、または自動初期化を無効にする
アプリでは多数のライブラリを使用します。起動に不可欠なライブラリがある一方で、大半のライブラリは、最初のフレームが描画されるまで初期化を遅延しても構わない場合があります。一部のライブラリは、起動時の自動初期化を無効にするオプションや、オンデマンド初期化を備えています。こうしたオプションを使用すると、必要になるまで初期化を延期してパフォーマンスを向上させることができます。たとえば、オンデマンド初期化を使用し、必要なときにのみ WorkManager を呼び出すことができます。
ViewStub を使用する
ViewStub
は、目に見えないゼロサイズの View
であり、これを使用するとレイアウト リソースのインフレートを実行時に遅延できます。そうすることで、起動時に不要なビューのインフレートを遅らせることができます。
Jetpack Compose を使用している場合は、ステータス情報に基づいて一部のコンポーネントの読み込みを遅らせることで、ViewStub
と同様の効果が得られます。
var shouldLoad by remember {mutableStateOf(false)}
if (shouldLoad) {
MyComposable()
}
shouldLoad
を変更して、条件ブロック内のコンポーザブルを読み込みます。
LaunchedEffect(Unit) {
shouldLoad = true
}
これにより、最初のスニペットの条件ブロック内にあるコードを含む再コンポーズがトリガーされます。
スプラッシュ画面を最適化する
スプラッシュ画面はアプリ起動の大部分を占めます。適切に設計されたスプラッシュ画面を使用すれば、アプリ起動のエクスペリエンスを全体的に改善できます。Android 12(API レベル 31)以降には、パフォーマンスを向上させるために設計されたスプラッシュ画面があります。詳細については、スプラッシュ画面をご覧ください。
スケーラブルな画像を使用する
画像にはベクター型ドローアブルを使用することをおすすめします。それが不可能な場合は、WebP 画像を使用します。WebP は、ウェブ上の画像に対する高品質な可逆圧縮と非可逆圧縮が可能な画像形式です。既存の BMP、JPG、PNG、静的 GIF 画像は、Android Studio を使用して WebP 形式に変換できます。詳しくは、WebP 画像を作成するをご覧ください。
起動時に読み込む画像の数とサイズを最小限にするのも重要です。
メディア再生用のパフォーマンス API は、Android 12(API レベル 31)以降で使用できます。この API を利用することで、デバイスの能力を把握して、それに応じたオペレーションを実行できるようになります。
コールド スタートアップのトレースを優先する
コールド スタートとは、アプリをゼロから起動することです。つまり、その時点ではシステムのプロセスがアプリのプロセスをまだ作成していません。デバイスが起動してから初めてアプリを起動する場合や、システムがアプリを強制停止した場合、通常、アプリはコールド スタートします。コールド スタートは非常に低速です。これは、他の起動タイプ(ウォーム スタートやホットスタートなど)では不要な処理がアプリとシステムで多数実行されるためです。コールド スタートアップのシステム トレースを行うことで、アプリのパフォーマンスをより正確に監視できます。
あなたへのおすすめ
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# Best practices for app optimization\n\nThe following best practices help optimize your app without sacrificing quality.\n\nUse Baseline Profiles\n---------------------\n\n[Baseline Profiles](/topic/performance/baselineprofiles/overview) can improve\ncode execution speed by 30% from the first launch, and can make all user\ninteractions---such as app startup, navigating between screens, or scrolling\nthrough content---smoother from the first time they run. Increasing the speed and\nresponsiveness of an app leads to more daily active users and a higher average\nreturn visit rate.\n\nUse a startup profile\n---------------------\n\nA\n[startup profile](/topic/performance/baselineprofiles/dex-layout-optimizations#startup-profiless)\nis similar to a Baseline Profile, but it is run at compile time to optimize the\nDEX layout for faster app startup.\n\nUse the App Startup library\n---------------------------\n\nThe [App Startup library](/topic/libraries/app-startup) lets you define\ncomponent initializers that share a single content provider, instead of defining\nseparate content providers for each component you need to initialize. This can\nsignificantly improve app startup time.\n\nLazily load libraries or disable auto-initialization\n----------------------------------------------------\n\nApps consume many libraries, some of which might be mandatory for startup.\nHowever, there can be many libraries where initialization can be delayed until\nafter the first frame is drawn. Some libraries have an option to disable\nauto-initialization on startup or have an on-demand initialization. Use this\noption to postpone initialization until necessary to help boost performance. For\nexample, you can use\n[on-demand initialization](/topic/libraries/architecture/workmanager/advanced/custom-configuration)\nto only invoke WorkManager when the component is required.\n\nUse ViewStubs\n-------------\n\nA [`ViewStub`](/reference/android/view/ViewStub) is an invisible, zero-sized\n`View` that you can use to lazily inflate layout resources at runtime. This\nlets you delay inflating views that aren't necessary at startup until a later\ntime.\n\nIf you are using Jetpack Compose, you can get similar behavior to `ViewStub`\nusing state to defer loading some components: \n\n var shouldLoad by remember {mutableStateOf(false)}\n\n if (shouldLoad) {\n MyComposable()\n }\n\nLoad the composeables inside the conditional block by modifying `shouldLoad`: \n\n LaunchedEffect(Unit) {\n shouldLoad = true\n }\n\nThis triggers a recomposition that includes the code inside the conditional\nblock in the first snippet.\n\nOptimize your splash screen\n---------------------------\n\nSplash screens are a major part of app startup, and using a well-designed\nsplash screen can help improve the overall app startup experience. Android\n12 (API level 31) and later includes a splash screen designed to improve\nperformance. For more information, see [Splash\nscreen](/about/versions/12/features/splash-screen).\n\nUse scalable image types\n------------------------\n\nWe recommend using [vector\ndrawables](/develop/ui/views/graphics/vector-drawable-resources) for images.\nWhere it's not possible, use [WebP\nimages](https://developers.google.com/speed/webp/). WebP is a image format\nthat provides superior lossless and lossy compression for images on the web. You\ncan convert existing BMP, JPG, PNG or static GIF images to WebP format using\nAndroid Studio. For more information, see [Create WebP\nimages](/studio/write/convert-webp).\n\nAdditionally, minimize the number and size of images loaded during startup.\n\nUse Performance APIs\n--------------------\n\nThe [performance API for media\nplayback](/about/versions/12/features/performance-class) is available on Android\n12 (API level 31) and later. You can use this API to understand device\ncapabilities and perform operations accordingly.\n\nPrioritize cold startup traces\n------------------------------\n\nA [cold start](/topic/performance/vitals/launch-time#cold) refers to an app\nstarting from scratch. Meaning, the system's process doesn't yet create the\napp's process. Your app typically starts cold if you launch it for the first\ntime since the device booted or since the system force-stopped the app. Cold\nstarts are much slower because the app and system must perform more work that\nisn't required on other startup types---like warm and hot starts. System tracing\ncold startups gives you better oversight into app performance.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [App startup analysis and optimization {:#app-startup-analysis-optimization}](/topic/performance/appstartup/analysis-optimization)\n- [App startup time](/topic/performance/vitals/launch-time)\n- [Frozen frames](/topic/performance/vitals/frozen)"]]