When app being launched, how to determine it is cold start or not? By cold start, I mean the app launched from the very beginning, instead of just resumed from a previous state.
:Edit: elaborate my question: I'm trying to find the app's launch mode: cold start or warm start. Cold start means the app is never launched before or not in background, so it needs a complete launch. Warm start means it is still in background, so it can resume and start faster. How to distinguish these two start modes programmatically?
I learnt about Cold Start in Android while working on Android Development at Oodles Technologies. Let me share my knowledge.
Splash Screen Also Known as Cold Start
Splash screen is an activity that will show for some time when your app is starting and after some time redirect to application main activity.
When to use splash screen :
To show your brand logo user. To load data from network or other source while showing splash screen. Android splash screen is used so that apps can show their icons before showing other content of the app. Splash is also used to do some background work in application for example loading resources from network while the splash screen is being shown. It will give a smooth look to the app.
Cold Start is also known as splash screen,launch screen or cold start in android.As per my opinion, users should have the content available as soon as possible for any app, but when a user launch an application, Android creates a new process , during it shows a black or white screen to user which is built in with application theme, or the theme of the activity that is the entry point.There can be more load if our application is more complex and using application object,which is normally used to initialize the analytics, error reporters, etc. i.e why black or white screen is not a good thing to show to user. If application load time is slow, we could use a place holder to simply fill it by real content, or on the other hand, if our workload is complex, we could show the logo of our application to make application look beautiful.
As we have discussed before, the window displayed by the window manager when the process is in the loading state is set up in the application theme(values>Style section).
Specifically with the value inside android:WindowBackground, you can make the splash or cold start by making a with the color of the background of the main activity over a small bitmap in the center.
The layer_list must be opaque .And the background color should be filled with a color in your main layout, if not the layerlist will always shown in the activity.
activity_splash.xml
SplashActivity.java
If the app is still running in the background it will call onResume first and not onCreate at all.
If you mean the first time it was ever launched on a device then use sqlite or shared preferences to store data and at the beginning check to see if its there.