Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Android’s Activities and Tasks

On Android, one activity can start another activity by using Intent. A task is a stack of activities that relates. The activity starts another activity with Intent, which is pushed to the same stack, and it is popped by the Back button. This is the standard behavior of Android. However, this behavior of the task can be changed by flags given to the Intent and attributes of the activities.

The page “Application Fundamentals” explains this very well. I wanted to know how to use these flags and attributes actually, so I looked for examples.

[1] Sharing from gallery

In the AndroidManifest.xml file of the gallery application, the clearTaskOnLauch attribute is True. So, if you start another activity from the gallery and back to the home, then you can start just a gallery screen by launching the gallery application. Because started activities were cleared when returning to the home.

[2] Starts Gmail from other application

In AndroidManifest.xml of Gmail, the allowTaskReparentng attribute is True. So, the Gmail activity started from other applications that are stacked to a task will move to a new task that has the same affinity as Gmail when the task comes to the foreground. For example,

・starts Gmail, and makes a new message
・return to the home
・starts Gallery, and share some pictures to Gmail
・return to the home

Because the Launch mode of Gmail is neither a single task nor a single instance, at this time there are two tasks 1) Gmail message list – making new messages 2) Gallery – sharing pictures with Gmail.

・ switch to task 1) by starting Gmail.

Then, a screen for sharing pictures is appearing, and by Back button, making new message screen appears. It seems that sharing pictures with Gmail activity of 2) moves to task 1).

[3] Page sharing from a browser

a launch mode of Browser is singleTask. It means the browser is always the route of the task. If some activity starts Browser, It can’t push Browser activity to its own stack. The browser starts a new task. And, the alwaysRetainTaskState attribute is True, which means the state of the task is retained.

However, If you start other applications from the browser, return to the home, and start the browser again, then the browser screen appears. Why?

When the browser starts other applications by “Share page”, the flag named FLAG_ACTIVITY_PREVIOUS_IS_TOP is set to Intent. This flag means that the activity starts with the Intent and seems to finish soon, so regard the previous activity as a top activity of the task. So when you switch the task to the browser, the browser itself is regarded as a top activity of the task. ( I’m not sure if this is true or not)

************************************************************************************************************

This framework of activities and tasks is not for general Android users, but for developers.

I think that developers should design the behavior of activities and tasks in a way that the ordinary user can use without being conscious of the rules. No strange behavior and behave as the same as expected by the user are good designs.

PAGE TOP