[Android Samples視頻系列之ApiDemos] App-Activity-Reorder Activities

來源:互聯網
上載者:User

1.Demo說明與示範

該Demo主要示範FLAG_ACTIVITY_REORDER_TO_FRONT的使用


如下:


2.視頻講解
http://www.eyeandroid.com/thread-10717-1-1.html

3.Demo分析

Reorder Activities 樣本有四個相關的Activitives: ReorderOnLaunch, ReorderTwo,ReorderThree, ReorderFour。其中ReorderOnLaunch為主Activity,ReorderOnLaunch啟動ReorderTwo ,ReorderTwo啟動 ReorderThree,ReorderThree啟動 ReorderFour。 這時在Activity的”back stack”有如下狀態:

 

ReorderFour 想再啟動ReorderTwo, 這時用兩種實現方法,一是在 RecordFour之上再啟動一個新的 ReorderTwo ,這是startActivity的預設行為。這是因為在AndroidManifest.xml

<activity android:name=”.app.ReorderTwo” />
<activity android:name=”.app.ReorderThree” />
<activity android:name=”.app.ReorderFour” />

.app.RecordTwo沒有定義任何這個Intent的Flag。 比如有 FLAG_ACTIVITY_NEW_TASK,FLAG_ACTIVITY_CLEAR_TOP,FLAG_ACTIVITY_SINGLE_TOP,在這些情況下 Android將根據不同Flag設定來決定啟動RecordTwo的方法,具體在後面的例子會有介紹。

在Reorder Activities例子中,是將“Back Stack”中的ReorderTwo移到棧頂,方法是在啟動Intent時設定Intent.FLAG_ACTIVITY_REORDER_TO_FRONT。如果設定了FLAG_ACTIVITY_REORDER_TO_FRONT表示將“Back Stack”中指定的Activity移動到棧頂。

 
  1. Intent intent = new Intent(ReorderFour.this, ReorderTwo.class);  
  2. intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);  
  3. startActivity(intent);  

 

此時棧如所示:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.