Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3428

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T02:38:08+00:00 2024-11-26T02:38:08+00:00

How not to let the cold app start on Android scare away your users

  • 61k

When creating an application, mobile developers aim to create a fast and high-quality product. The impression of the user who tries out your application depends on it. If the application launch is slow and unpleasant, the users will be disappointed even before they try out your application.

Let’s take a look at what types of app launches there are

An app can start in one of three states: cold start, warm start, or hot start. The difference is the startup time that it takes to make your app visible to the user. With the cold start, your application is built and launched from scratch. It may take longer than in the other two states, where the application is simply brought to the foreground as it already exists on the stack.

Alt Text

Cold start

With the cold start, the system process did not create an application process before that start. Usually, a cold start happens when you have just installed and launched an application or when you launch an application that was in a completed state. This kind of state is more problematic than other states, since it is during a cold start that a number of complex tasks are performed. So the user can see a white screen for some time before the app screens open for interaction.

Application Cold Start Example.

Click event gets translated into startActivity(intent), and it is routed to ActvityManagerService via Binder IPC. The ActvityManagerService performs multiple steps.

Diagram with ActivityManagerService Processes via Binder IPC.

  1. The first step is to collect information about the target of the intent object. This is done by using the resolveIntent() method on the PackageManager object. PackageManager.MATCH_DEFAULT_ONLY and PackageManager.GET_SHARED_LIBRARY_FILES flags are used by default.

  2. The target information is saved back into the intent object to avoid re-doing this step.

  3. The next important step is to check if the user has enough privileges to invoke the target component of the intent. This is done by calling the grantUriPermissionLocked() method.

  4. If the user has enough permissions, ActivityManagerService checks if the target activity requires to be launched in a new task. The task creation depends on Intent flags like FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TOP.

Now, it’s time to check if the ProcessRecord already exists for the process. If the ProcessRecord is null, the ActivityManager has to create a new process to instantiate the target component.

Hot start

A hot start is when your app’s actions are in the memory and your app’s process is already running in the background. With a hot start, all the system needs to do is bring your app’s activity to the fore. This makes it much faster because the system doesn’t need to re-initialize, so the overhead is much lower.

Application Start Example.

If the user brings back activity from the Recents screen instead of tapping a launcher icon, the system process calls TaskSnapshotSurface.create() to create a starting window that draws a saved snapshot of the activity.

If some memory was cleared in response to memory pruning events, such as onTrimMemory (), then these objects will need to be recreated in response to a hot start event, in which case hot start displays the same behavior as cold start, that is, the system process displays a blank screen until the application completes rendering the action.

How to make a cold start more pleasant and prevent bad user experience?

Each user, when interacting with the app, expects to have access to the content as soon as possible, and this “start” content can be displayed with a background or the app logo.

So, to create your own background, you need to create an xml file in the drawable folder and add the desired colors:

<?xml version="1.0" encoding="utf-8"?> <shape  xmlns:android="http://schemas.android.com/apk/res/android">  <gradient     android:angle="45"     android:endColor="#87CEEB"     android:centerColor="#768087"     android:startColor="#000"     android:type="linear" />  </shape> 
Enter fullscreen mode Exit fullscreen mode

Next, the background has to be set in the application topic (values >themes.xml section) :

<item name="android:windowBackground">@drawable/bg_splash</item> 
Enter fullscreen mode Exit fullscreen mode

Also, as an input point for the app, you can add the SplashActivity screen, which will be displayed immediately after the app starts and forms a smooth transition so that the user does not notice much difference:

<activity android:name=".SplashActivity"> <intent-filter>     <action android:name="android.intent.action.MAIN" />      <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 
Enter fullscreen mode Exit fullscreen mode

As content, you can use the application logo and the background that was added for the start window:

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout  xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg_splash" tools:context=".SplashActivity">      <TextView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:fontFamily="@font/rokkitt_bold"     android:text="@string/example_app"     android:textColor="@android:color/white"     android:textSize="30sp"     app:layout_constraintBottom_toBottomOf="parent"     app:layout_constraintLeft_toLeftOf="parent"     app:layout_constraintRight_toRightOf="parent"     app:layout_constraintTop_toTopOf="parent" />  </androidx.constraintlayout.widget.ConstraintLayout> 
Enter fullscreen mode Exit fullscreen mode

In the activity itself, you need to wrap the Intent in a Handler, which opens the interaction screen after the specified time has elapsed:

class SplashActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {     super.onCreate(savedInstanceState)     setContentView(R.layout.activity_splash)          Handler(Looper.getMainLooper()).postDelayed({         /* Create an Intent that will start the MainActivity. */         val mainIntent = Intent(this, MainActivity::class.java)         startActivity(mainIntent)         finish()     }, 800) 
Enter fullscreen mode Exit fullscreen mode

And finally, don’t forget to add color to the MainActivty content; otherwise, it will display the background that you set in the theme:

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout  xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" tools:context=".MainActivity">      <TextView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="Hello World!"     app:layout_constraintBottom_toBottomOf="parent"     app:layout_constraintLeft_toLeftOf="parent"     app:layout_constraintRight_toRightOf="parent"     app:layout_constraintTop_toTopOf="parent" />  </androidx.constraintlayout.widget.ConstraintLayout> 
Enter fullscreen mode Exit fullscreen mode

Now you can run the project and see the result:

Application Cold Start Example.

I hope it was useful and interesting for you!)

Check out the sample project on GitHub.

Mobile App Development.

Previously published at maddevs.io.

agiledevjournaltutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.