what is the best time to download android apps

Users expect apps to be responsive and fast to load. An app with a tiresome beginning time doesn't encounter this expectation, and tin can be disappointing to users. This sort of poor feel may cause a user to rate your app poorly on the Play store, or even abandon your app altogether.

This document provides data to help you optimize your app's launch fourth dimension. It begins past explaining the internals of the launch process. Next, it discusses how to contour startup functioning. Last, information technology describes some common offset-fourth dimension issues, and gives some hints on how to address them.

Understand the different app startup states

App launch tin take place in one of three states, each affecting how long information technology takes for your app to go visible to the user: cold start, warm commencement, or hot showtime. In a cold first, your app starts from scratch. In the other states, the system needs to bring the running app from the background to the foreground. We recommend that you always optimize based on an assumption of a cold beginning. Doing so can ameliorate the functioning of warm and hot starts, equally well.

To optimize your app for fast startup, it's useful to understand what'southward happening at the arrangement and app levels, and how they interact, in each of these states.

Cold start

A common cold showtime refers to an app's starting from scratch: the organization's process has non, until this commencement, created the app'south process. Cold starts happen in cases such equally your app's being launched for the first time since the device booted, or since the arrangement killed the app. This type of start presents the greatest claiming in terms of minimizing startup fourth dimension, because the organisation and app have more piece of work to do than in the other launch states.

At the offset of a cold showtime, the system has iii tasks. These tasks are:

  1. Loading and launching the app.
  2. Displaying a blank starting window for the app immediately subsequently launch.
  3. Create the app procedure.

As soon equally the system creates the app procedure, the app procedure is responsible for the next stages:

  1. Creating the app object.
  2. Launching the master thread.
  3. Creating the main activity.
  4. Inflating views.
  5. Laying out the screen.
  6. Performing the initial draw.

One time the app process has completed the starting time describe, the system process swaps out the currently displayed background window, replacing it with the principal activeness. At this bespeak, the user tin start using the app.

Figure one shows how the system and app processes hand off work between each other.

Figure one: A visual representation of the important parts of a cold application launch.

Functioning issues can arise during creation of the app and creation of the activity.

Application creation

When your awarding launches, the blank starting window remains on the screen until the system finishes drawing the app for the first fourth dimension. At that bespeak, the system process swaps out the starting window for your app, allowing the user to get-go interacting with the app.

If you've overridden Application.onCreate() in your own app, the system invokes the onCreate() method on your app object. Afterwards, the app spawns the main thread, also known every bit the UI thread, and tasks it with creating your main action.

From this indicate, arrangement- and app-level processes go along in accordance with the app lifecycle stages.

Activity creation

After the app process creates your activity, the activity performs the following operations:

  1. Initializes values.
  2. Calls constructors.
  3. Calls the callback method, such as Activity.onCreate(), advisable to the current lifecycle state of the activeness.

Typically, the onCreate() method has the greatest impact on load time, considering it performs the work with the highest overhead: loading and inflating views, and initializing the objects needed for the activity to run.

Warm first

A warm start encompasses some subset of the operations that take place during a cold start; at the same time, it represents more overhead than a hot beginning. There are many potential states that could be considered warm starts. For case:

  • The user backs out of your app, but then re-launches it. The process may have connected to run, but the app must recreate the action from scratch via a call to onCreate().

  • The organization evicts your app from memory, and and so the user re-launches it. The process and the activity need to be restarted, but the chore can benefit somewhat from the saved instance land bundle passed into onCreate().

Hot first

A hot get-go of your awarding is much simpler and lower-overhead than a cold kickoff. In a hot starting time, all the system does is bring your activity to the foreground. If all of your application's activities are still resident in memory, so the app tin avert having to repeat object initialization, layout inflation, and rendering.

However, if some retentiveness has been purged in response to memory trimming events, such every bit onTrimMemory() and then those objects volition need to be recreated in response to the hot first event.

A hot start displays the aforementioned on-screen beliefs as a cold start scenario:

The system process displays a blank screen until the app has finished rendering the activity.

Effigy 2: This diagram displays the various startup states and their respective processes, with each state commencement from the starting time frame drawn.

Using metrics to detect and diagnose bug

In social club to properly diagnose start time performance, you can track metrics that bear witness how long it takes your awarding to outset. Android provides several means of letting y'all know that your app has a problem, and to help you diagnose it. Android vitals can alarm you that the problem is occurring, and diagnostic tools can help you diagnose the trouble.

Benefits of utilizing startup metrics

Android uses the Time to initial display and Time to full display metrics to optimize cold and warm application startups. Android Runtime (ART) uses the data from these metrics to efficiently precompile code for optimization of future startups.

Faster startups atomic number 82 to more sustained user interaction with your app, which reduces instances of early exiting, restarting the instance, or navigating away to a different app.

Android vitals

Android vitals can help meliorate your app'southward operation by alerting y'all, via the Play Console, when your app's startup times are excessive. Android vitals considers your app's startup times excessive when the app's:

  • Cold startup takes 5 seconds or longer.
  • Warm startup takes 2 seconds or longer.
  • Hot startup takes 1.5 seconds or longer.

Android vitals uses the Time to initial display metric and doesn't study information for hot startups. For information on how Google Play collects Android vitals data, run into the Play Panel documentation.

Fourth dimension to initial display

The time to initial display (TTID) metric measures the time it takes for an application to produce its first frame, including process initialization (if a cold first), activity creation (if common cold/warm), and displaying first frame.

How to retrieve TTID

In Android four.4 (API level 19) and higher, logcat includes an output line containing a value called Displayed. This value represents the amount of fourth dimension elapsed between launching the process and finishing cartoon the corresponding activity on the screen. The elapsed fourth dimension encompasses the following sequence of events:

  • Launch the procedure.
  • Initialize the objects.
  • Create and initialize the activity.
  • Inflate the layout.
  • Draw your application for the first time.

The reported log line looks similar to the following example:

ActivityManager: Displayed com.android.myexample/.StartupTiming: +3s534ms        

If y'all're tracking logcat output from the control line, or in a terminal, finding the elapsed time is straightforward. To find elapsed time in Android Studio, you must disable filters in your logcat view. Disabling the filters is necessary because the system server, not the app itself, serves this log.

Once you've made the appropriate settings, y'all can easily search for the correct term to encounter the time. Figure 2 shows how to disable filters, and, in the 2d line of output from the lesser, an example of logcat output of the Displayed time.

Effigy 2: Disabling filters, and finding the `Displayed` value in logcat.

The Displayed metric in the logcat output does not necessarily capture the amount of fourth dimension until all resources are loaded and displayed: it leaves out resource that are non referenced in the layout file or that the app creates as role of object initialization. It excludes these resources because loading them is an inline process, and does not block the app's initial display.

Sometimes the Displayed line in the logcat output contains an additional field for total fourth dimension. For instance:

ActivityManager: Displayed com.android.myexample/.StartupTiming: +3s534ms (total +1m22s643ms)        

In this example, the first time measurement is only for the activeness that was offset fatigued. The total time measurement begins at the app process start, and could include some other activity that was started outset merely did non display anything to the screen. The total fourth dimension measurement is simply shown when there is a divergence betwixt the single activity and total startup times.

You can also measure out the fourth dimension to initial display past running your app with the ADB Shell Action Manager control. Hither's an example:

adb [-d|-e|-s <serialNumber>] shell am start -Southward -West com.instance.app/.MainActivity -c android.intent.category.LAUNCHER -a android.intent.action.Main

The Displayed metric appears in the logcat output equally before. Your concluding window should also display the following:

Starting: Intent Activity: com.example.app/.MainActivity ThisTime: 2044 TotalTime: 2044 WaitTime: 2054 Complete        

The -c and -a arguments are optional and let you specify <category> and <activity>

Time to full brandish

The Time to full brandish (TTFD) metric measures the fourth dimension taken by the application to produce its beginning frame with full content, including content loaded asynchronously after the first frame. More often than not, this is primary list content loaded from the network, as reported by the app.

How to retrive TTFD

Y'all tin can utilize the reportFullyDrawn() method to measure the elapsed time between application launch and consummate display of all resources and view hierarchies. This can exist valuable in cases where an app performs lazy loading. In lazy loading, an app does not block the initial drawing of the window, just instead asynchronously loads resource and updates the view hierarchy.

If, due to lazy loading, an app'south initial brandish does not include all resources, yous might consider the completed loading and display of all resources and views every bit a separate metric: For instance, your UI might be fully loaded, with some text fatigued, only non yet display images that the app must fetch from the network.

To accost this concern, you lot can manually call reportFullyDrawn() to let the organisation know that your activity is finished with its lazy loading. When y'all apply this method, the value that logcat displays is the time elapsed from the cosmos of the application object to the moment reportFullyDrawn() is chosen. Here's an example of the logcat output:

system_process I/ActivityManager: Fully drawn {parcel}/.MainActivity: +1s54ms

The logcat output sometimes includes a total fourth dimension, as discussed in Time to initial display.

If yous acquire that your display times are slower than you'd similar, you can keep to try to identify the bottlenecks in the startup process.

Identifying bottlenecks

A expert way to await for bottlenecks is to use the Android Studio CPU Profiler. For information, see Audit CPU activity with CPU Profiler.

You tin can also gain insight into potential bottlenecks through inline tracing inside of your apps' and activities' onCreate() methods. To learn nearly inline tracing, run into the documentation for the Trace functions, and the overview of system tracing.

Be aware of common issues

This department discusses several problems that often bear on apps' startup performance. These issues chiefly concern initializing app and activity objects, too as the loading of screens.

Heavy app initialization

Launch performance can suffer when your lawmaking overrides the Application object, and executes heavy work or circuitous logic when initializing that object. Your app may waste time during startup if your Application subclasses perform initializations that don't demand to be done yet. Some initializations may be completely unnecessary: for case, initializing state information for the main activity, when the app has actually started upwardly in response to an intent. With an intent, the app uses only a subset of the previously initialized state data.

Other challenges during app initialization include garbage-drove events that are impactful or numerous, or deejay I/O happening concurrently with initialization, further blocking the initialization procedure. Garbage collection is especially a consideration with the Dalvik runtime; the Art runtime performs garbage collection concurrently, minimizing that operation's bear upon.

Diagnosing the problem

You can apply method tracing or inline tracing to try to diagnose the problem.

Method tracing

Running the CPU Profiler reveals that the callApplicationOnCreate() method eventually calls your com.instance.customApplication.onCreate method. If the tool shows that these methods are taking a long time to finish executing, you should explore farther to see what work is occurring there.

Inline tracing

Employ inline tracing to investigate likely culprits including:

  • Your app'south initial onCreate() part.
  • Any global singleton objects your app initializes.
  • Any deejay I/O, deserialization, or tight loops that might exist occurring during the clogging.

Solutions to the problem

Whether the problem lies with unnecessary initializations or with deejay I/O, the solution is lazy initialization. In other words, you should only initialize objects that are immediately needed. Instead of creating global static objects, move to a singleton design where the app initializes objects only the first time information technology needs them.

Too, consider using a dependency injection framework like Hilt that creates objects and dependencies when they are injected for the first time.

If your app uses content providers to initialize app components at startup, consider using the App Startup library instead.

Heavy activity initialization

Activity cosmos often entails a lot of loftier-overhead work. Often, there are opportunities to optimize this piece of work to achieve functioning improvements. Such common problems include:

  • Inflating big or complex layouts.
  • Blocking screen cartoon on deejay, or network I/O.
  • Loading and decoding bitmaps.
  • Rasterizing VectorDrawable objects.
  • Initialization of other subsystems of the activity.

Diagnosing the problem

In this case, equally well, both method tracing and inline tracing can bear witness useful.

Method tracing

When using the CPU Profiler, pay attention to your app's Application subclass constructors and com.case.customApplication.onCreate() methods.

If the tool shows that these methods are taking a long time to terminate executing, you should explore further to run into what piece of work is occurring at that place.

Inline tracing

Utilise inline tracing to investigate probable culprits including:

  • Your app's initial onCreate() function.
  • Any global singleton objects it initializes.
  • Any disk I/O, deserialization, or tight loops that might be occurring during the bottleneck.

Solutions to the problem

There are many potential bottlenecks, but two common problems and remedies are every bit follows:

  • The larger your view hierarchy, the more than time the app takes to inflate it. 2 steps you lot can take to accost this issue are:

    • Flattening your view hierarchy by reducing redundant or nested layouts.

    • Not inflating parts of the. U. that do not need to exist visible during launch. Instead, use a ViewStub object as a placeholder for sub-hierarchies that the app can inflate at a more than appropriate time.

  • Having all of your resource initialization. on thursday. main thread can also slow downstartup.You can address this issue as follows:

    • Move all resource initialization then that the app can perform information technology lazily on a unlike thread.
    • Allow the appto. load and display your views, and thenlater update visual backdrop that are dependent on bitmaps and other resources.

Custom splash screens

You lot may see actress time added during startup if you take previously used i of the following methods to implement a custom splash screen in Android 11 (API level 30) or lower:

  • Using the windowDisablePreview theme attribute to plough off the initial blank screen drawn by the arrangement during launch.

  • Using a dedicated Action

Starting with Android 12, migrating to the SplashScreen API is required. This API enables a faster startup fourth dimension, and too allows you to tweak your splash screen in the following means:

  • Set a theme to change the splash screen's appearance
  • Control how long the splash screen is displayed
  • Determine how much more time the splash screen blitheness needs, and gracefully handle the blitheness for dismissing the splash screen

Furthermore, the compat library backports the SplashScreen API to enable backward-compatibility and to create a consequent look and experience for splash screen brandish beyond all Android versions.

See the Splash screen migration guide for details.

chessonoctaires.blogspot.com

Source: https://developer.android.com/topic/performance/vitals/launch-time

0 Response to "what is the best time to download android apps"

ارسال یک نظر

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel