Pull to refresh

Comments 6

Помню разбирался с launchMode с документацией, исходниками и методом проб и ошибок. И мне кажется в итоге сделал всё криво. Спасибо за статью.

чё-то нифига в итоге не понял, кроме того что "там всё криво и нормально этим воспользоваться нельзя"...

Кажется, атрибут android:allowTaskReparenting в тегах application или activity в манифесте, радикально влияет на описываемое поведение и просто обязан был быть тут упомянут.

Whether the activity can move from the task that started it to the task it has an affinity for when that task is next brought to the front. It's "true" if it can move, and "false" if it remains with the task where it started.

If this attribute isn't set, the value set by the corresponding allowTaskReparenting attribute of the <application> element applies to the activity. The default value is "false".

Normally, when an activity is started it's associated with the task of the activity that started it and it stays there for its entire lifetime. You can use this attribute to force it to be re-parented to the task it has an affinity for when its current task is no longer displayed. Typically, this is used to cause the activities of an application to move to the main task associated with that application.

For example, if an email message contains a link to a web page, clicking the link brings up an activity that can display the page. That activity is defined by the browser application but is launched as part of the email task. If it's reparented to the browser task, it shows when the browser next comes to the front and is absent when the email task again comes forward.

The affinity of an activity is defined by the taskAffinity attribute. The affinity of a task is determined by reading the affinity of its root activity. Therefore, by definition, a root activity is always in a task with the same affinity. Since activities with "singleTask" or "singleInstance" launch modes can only be at the root of a task, re-parenting is limited to the "standard" and "singleTop" modes. (See also the launchMode attribute.)

Так же в тему атрибут android:documentLaunchMode:

Specifies how a new instance of an activity is added to a task each time it is launched. This attribute permits the user to have multiple documents from the same application appear in the Recents screen.

This attribute has four values, which produce the following effects when the user opens a document with the application:

"intoExisting"The system searches for a task whose base intent's ComponentName and data URI match those of the launching intent. If the system finds such a task, the system clears the task and restarts, with the root activity receiving a call to onNewIntent(android.content.Intent). If the system doesn't find such a task, the system creates a new task.

"always"The activity creates a new task for the document, even if the document is already opened. This is the same as setting both the FLAG_ACTIVITY_NEW_DOCUMENT and FLAG_ACTIVITY_MULTIPLE_TASK flags.

"none"The activity doesn't create a new task for the activity. This is the default value, which creates a new task only when FLAG_ACTIVITY_NEW_TASK is set. The Recents screen treats the activity as it does by default: it displays a single task for the app, which resumes from whatever activity the user last invoked.

"never"The activity isn't launched into a new document even if the intent contains FLAG_ACTIVITY_NEW_DOCUMENT. Setting this overrides the behavior of the FLAG_ACTIVITY_NEW_DOCUMENT and FLAG_ACTIVITY_MULTIPLE_TASK flags, if either of these are set in the activity, and the Recents screen displays a single task for the app, which resumes from whatever activity the user last invoked.

Note: For values other than "none" and "never", the activity is defined with launchMode="standard". If this attribute isn't specified, documentLaunchMode="none" is used.

Sign up to leave a comment.