[Points] Task and Back Stack

Task and Back Stack

  • a new task is created and the "main" activity for that app opens as the root activity in the stack
  • new activity is pushed on the top of the stack
  • pressed back the top activity pop from stack
  • no activity no task
  • Home screen make task background
  • one activity can get multiple instants(Figure 1)

                               

                                    Figure 1

  • implememt onSaveInstanceState() save activity state because activity may be detroyed in backgroud

Managing Tasks

 

  • android:taskAffinity( set activity belong to which task. as default all activity in same application using same taskAffinity )
  • android:launchMode (standard,singleTop,singleTask,singleInstance)
  • intent_filter (FLAG_ACTIVITY_NEW_TASK,FLAG_ACTIVITY_CLEAR_TOP,FLAG_ACTIVITY_SINGLE_TOP)

Caution: Most applications should not interrupt the default behavior for activities and tasks.

Defining launch modes

  • using the manifest file
  • using intent filter flag
  • A start B ,Activity A's request (as defined in the intent) is honored over (以A为准?) Activity B's request (as defined in its manifest).

Note: Some launch modes available for the manifest file are not available as flags for an intent and, likewise, some launch modes available as flags for an intent cannot be defined in the manifest.

  • the web browser activity should always open in its own task—by specifying the singleTask
  • if you start an activity that specifies the singleTask launch mode, then if an instance of that activity exists in a background task, that whole task is brought to the foreground.(Figure 2)

                                     

                                                                    Figure 2

Clear the back stack

  • if the user leaves a task for a long time, the system clears the task of all activities except the root activity. When the user returns to the task again, only the root activity is restored.
  • modify system clear task way
  1. alwaysRetainTaskState (retains all activities in its stack)
  2. clearTaskOnLaunch (clear all activities in its stack when user leaving this stack)
  3. finishOnTaskLaunch (clear just this activity when user leaving its stack)

Starting a task

  • stark task with "android.intent.action.MAIN" as the specified action and "android.intent.category.LAUNCHER" as the specified category(in AndroidManifest)

转载于:https://www.cnblogs.com/jsaint/articles/3448447.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值