android LocalActivityManager說明

來源:互聯網
上載者:User

標籤:

   類概述

Helper class for managing multiple running embedded activities in the same process. This class is not normally used directly, but rather created for you as part of theActivityGroup implementation.

 

首先說明一下,意思就是說這個類不能單獨使用,只能在ActivityGroup裡面使用。他的作用是管理多個正在啟動並執行嵌入的activity的介面。。。

 

關於成員方法的說明:

其實看SDK也就可以知道了。。。

主要的就是派遣方法,讓某一個操作可以作用於在這個ActivityGroup裡面的Activity

 

Window destroyActivity(String id, boolean finish)摧毀該ID的activity。。。。並且返回你刪除的activity的view。。。Destroy the activity associated with a particular id.
void dispatchCreate(Bundle state)Restore a state that was previously returned by saveInstanceState().
void dispatchDestroy(boolean finishing)Called by the container activity in its onDestroy() so that LocalActivityManager can perform the corresponding action on the activities it holds.
void dispatchPause(boolean finishing)Called by the container activity in its onPause() so that LocalActivityManager can perform the corresponding action on the activities it holds.
void dispatchResume()Called by the container activity in its onResume() so that LocalActivityManager can perform the corresponding action on the activities it holds.
void dispatchStop()Called by the container activity in its onStop() so that LocalActivityManager can perform the corresponding action on the activities it holds.
Activity getActivity(String id)Return the Activity object associated with a string ID.
Activity getCurrentActivity()Retrieve the Activity that is currently running.
String getCurrentId()Retrieve the ID of the activity that is currently running.
void removeAllActivities()Remove all activities from this LocalActivityManager, performing an onDestroy() on any that are currently instantiated.
Bundle saveInstanceState()Retrieve the state of all activities known by the group.
Window startActivity(String id, Intent intent)Start a new activity running in the group.

 

下面主要說明一下startActivity(String id, Intent intent)這個方法:

 

Start a new activity running in the group. Every activity you start must have a unique string ID associated with it -- this is used to keep track of the activity, so that if you later call startActivity() again on it the same activity object will be retained.

When there had previously been an activity started under this id, it may either be destroyed and a new one started, or the current one re-used, based on these conditions, in order:

  • If the Intent maps to a different activity component than is currently running, the current activity is finished and a new one started.
  • If the current activity uses a non-multiple launch mode (such as singleTop), or the Intent has the FLAG_ACTIVITY_SINGLE_TOP flag set, then the current activity will remain running and its Activity.onNewIntent() method called.
  • If the new Intent is the same (excluding extras) as the previous one, and the new Intent does not have the FLAG_ACTIVITY_CLEAR_TOP set, then the current activity will remain running as-is.
  • Otherwise, the current activity will be finished and a new one started.

If the given Intent can not be resolved to an available Activity, this method throws ActivityNotFoundException.

Warning: There is an issue where, if the Intent does not include an explicit component, we can restore the state for a different activity class than was previously running when the state was saved (if the set of available activities changes between those points).

參數
id Unique identifier of the activity to be started
intent The Intent describing the activity to be started
傳回值
  • Returns the window of the activity. The caller needs to take care of adding this window to a view hierarchy, and likewise dealing with removing the old window if the activity has changed.
簡單的翻譯一下就是:

 

建立並且運行一個activity在activitygroup裡面,主要的說明就在這個String id裡面,說盡量在建立時候不要是用同一個

id,因為這個樣子就會到導致如果你使用再一次 startActivity() ,那麼就會繼續保留下去。。。

當這個activity需要被銷毀的時候:

如果有以下的情況就可以不用銷毀。其他都需要銷毀。。。

1.已經有一個老的intent,而且新的intent沒有使用FLAG_ACTIVITY_CLEAR_TOP 這個參數

2.當前的activity使用的是uses a non-multiple launch mode 的話

3.intent還有不從的介面組件。。。

 

 

android LocalActivityManager說明

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.