[Samsung DeX] Android Life Cycle in Samsung DeX

Samsung Developer Program

Samsung DeX allows the user to run their Android application in a desktop like environment i.e. interacting with mouse, keyboard and launching multiple applications on the same screen and switching between multiple applications with ease. Now your application will have features to minimize, maximize, close and resize the width and height of your activity according to your needs. As soon as the developer listens about all these features he would be little worried about how the android life cycle methods are invoked in all these scenario and how we will be writing code for better utilization of these features in an optimal way.

So, this blog will tell you how android life cycle methods are executed in Samsung DeX mode for all these scenarios.

So, let’s get started!!!

For better understanding about android life cycle in Samsung DeX, I will be taking the example of two applications say App1 and App2 to describe about each scenario. Initially you can assume that both the applications App1 and App2 are already launched and they are side by side on the screen.

1. Application going in background and foreground

In this scenario both the applications are visible to user. You can assume that you are writing something in your favourite editor say App1. So in this case your App1 is in the foreground and App2 is in the background. When you switch from App1 to App2 like scrolling some web pages in App2, App1 will go to the background and App2 will come to the foreground.

As for the life cycle is concerned:

1.1. Going to background:

The application status is changed to "Paused".

onPause() callback is called.

1.2. Going to Foreground:

The application status is changed back to "Running".

onResume() callback is called.

2. Application not visible to the user

Case 1:

This scenario comes when user presses minimize button of window in their application. Application goes to the taskbar and is not visible to the user.

Case 2:

When one application gets covered by maximized window of another application. This scenario occurs when the user presses maximize button of window in their application.

For example:

In this scenario, only one application is visible to user in full window. You can assume that you are writing something in your favourite editor say App1 and you suddenly decided to maximize the window to full size covering the other Application say App2, then App2 will be fully covered by maximized window of App1.

As for the life cycle is concerned:

2.1. Application is on taskbar or hidden by another full screen application.

For example:

when user presses minimize button of window or when one application gets covered by maximized window of another application.

The application status is changed to "Stopped".

onPause() and onStop() callbacks are sequentially called for App2.

2.2. Application launched from taskbar or other application not covering full screen.

For example:

Application going back to original-size window from taskbar or when App1 which is in full size, moves to its previous size or is not covering the full screen.

The application status is changed back to "Running".

onRestart(), onStart() and onResume() callbacks are sequentially called.

3. Close Window in Application

This scenario occurs when the user presses the close button of application window in his application.

As for the life cycle is concerned:

The app status is changed to "Destroyed".

onPause(), onStop() and onDestroy() callbacks are sequentially called.

4. Resizing the window size for an app

When the user resizes the Application screen size i.e. screen width, screen height, screen layout, smallest screen size, screen orientation are changed. So, if you declare below configuration changes in your manifest file then android doesn't kill and restart your activity every time when the window is resized.

Case 1:

When you make the following configuration changes in your manifest file for each activity, android will not kill and restart your activity every time you resize your window.

<activity android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize>

If the application has added the android:configChanges flag to the activity's Manifest, application would not be recreated and onConfigurationChanged() callback would be called.

Case 2:

If application does not add the android:configChanges flag to the activity's Manifest, application would be destroyed and recreated every time the user resizes the window.

For information about how the android life cycle works on switching between mobile to Samsung DeX mode or vice versa please refer: Lifecycle on switching between Mobile and Samsung DeX mode.