Home | History | Annotate | Download | only in components
      1 page.title= 
      2 page.tags="recents","overview"
      3 
      4 @jd:body
      5 
      6 <div id="qv-wrapper">
      7 <div id="qv">
      8 
      9   <h2> </h2>
     10   <ol>
     11     <li><a href="#adding">    </a>
     12       <ol>
     13         <li><a href="#flag-new-doc">  Intent   </a></li>
     14         <li><a href="#attr-doclaunch">     </a></li>
     15       </ol>
     16     </li>
     17     <li><a href="#removing"> </a>
     18       <ol>
     19         <li><a href="#apptask-remove">  AppTask   </a></li>
     20         <li><a href="#retain-finished">  </a></li>
     21       </ol>
     22     </li>
     23   </ol>
     24 
     25   <h2> </h2>
     26   <ol>
     27     <li>{@link android.app.ActivityManager.AppTask}</li>
     28     <li>{@link android.content.Intent}</li>
     29   </ol>
     30 
     31   <h2> </h2>
     32   <ol>
     33     <li><a href="{@docRoot}samples/DocumentCentricApps/index.html">    </a></li>
     34   </ol>
     35 
     36 </div>
     37 </div>
     38 
     39 <p>  (  :   ,      )
     40      ,      <a href="{@docRoot}guide/components/activities.html">
     41 </a>  <a href="{@docRoot}guide/components/tasks-and-back-stack.html"></a>. 
     42         ,    
     43  .   Android 5.0 ( API 21)  
     44  ,   ,        . ,
     45 Google          Google.     
     46    .</p>
     47 
     48 <img src="{@docRoot}images/components/recents.png" alt="" width="284" />
     49 <p class="img-caption"><strong> 1.</strong>  ,      Google ,
     50      .</p>
     51 
     52 <p>         
     53    .      .
     54            .   
     55 {@link android.app.ActivityManager.AppTask}   ,      
     56 {@link android.content.Intent} ,      
     57    .  ,  <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">
     58 &lt;activity&gt;</a></code>     .</p>
     59 
     60 <h2 id="adding">    </h2>
     61 
     62 <p>   {@link android.content.Intent}      
     63           .   
     64 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>
     65          
     66    .</p>
     67 
     68 <h3 id="flag-new-doc">  Intent   </h3>
     69 
     70 <p>        
     71 {@link android.app.ActivityManager.AppTask#startActivity(android.content.Context, android.content.Intent, android.os.Bundle) startActivity()}
     72  {@link android.app.ActivityManager.AppTask},   intent,
     73   .    ,       
     74    ,   {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT}
     75   {@link android.content.Intent#addFlags(int) addFlags()} {@link android.content.Intent},
     76   .</p>
     77 
     78 <p class="note"><strong>.</strong>  {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT}
     79   {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET},
     80      Android 5.0   ( API 21).</p>
     81 
     82 <p>    {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK}  
     83  ,           .
     84         .   ,
     85     :</p>
     86 
     87 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">
     88 DocumentCentricActivity.java</a></p>
     89 <pre>
     90 public void createNewDocument(View view) {
     91       final Intent newDocumentIntent = newDocumentIntent();
     92       if (useMultipleTasks) {
     93           newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
     94       }
     95       startActivity(newDocumentIntent);
     96   }
     97 
     98   private Intent newDocumentIntent() {
     99       boolean useMultipleTasks = mCheckbox.isChecked();
    100       final Intent newDocumentIntent = new Intent(this, NewDocumentActivity.class);
    101       newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    102       newDocumentIntent.putExtra(KEY_EXTRA_NEW_DOCUMENT_COUNTER, incrementAndGet());
    103       return newDocumentIntent;
    104   }
    105 
    106   private static int incrementAndGet() {
    107       Log.d(TAG, "incrementAndGet(): " + mDocumentCounter);
    108       return mDocumentCounter++;
    109   }
    110 }
    111 </pre>
    112 
    113 <p class="note"><strong>.</strong> ,    {@code FLAG_ACTIVITY_NEW_DOCUMENT},
    114     {@code android:launchMode="standard"} ( ), 
    115  .</p>
    116 
    117 <p>     ,      ,
    118  intent       Intent  .  
    119    intent   {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK},
    120        .   ,  
    121           intent  {@link android.app.Activity#onNewIntent onNewIntent()}.
    122    intent       , 
    123   :</p>
    124 
    125 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">
    126 NewDocumentActivity.java</a></p>
    127 <pre>
    128 &#64;Override
    129 protected void onCreate(Bundle savedInstanceState) {
    130     super.onCreate(savedInstanceState);
    131     setContentView(R.layout.activity_new_document);
    132     mDocumentCount = getIntent()
    133             .getIntExtra(DocumentCentricActivity.KEY_EXTRA_NEW_DOCUMENT_COUNTER, 0);
    134     mDocumentCounterTextView = (TextView) findViewById(
    135             R.id.hello_new_document_text_view);
    136     setDocumentCounterText(R.string.hello_new_document_counter);
    137 }
    138 
    139 &#64;Override
    140 protected void onNewIntent(Intent intent) {
    141     super.onNewIntent(intent);
    142     /* If FLAG_ACTIVITY_MULTIPLE_TASK has not been used, this activity
    143     is reused to create a new document.
    144      */
    145     setDocumentCounterText(R.string.reusing_document_counter);
    146 }
    147 </pre>
    148 
    149 
    150 <h3 id="#attr-doclaunch">     </h3>
    151 
    152 <p>     ,       .    
    153 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>
    154 , <a href="{@docRoot}guide/topics/manifest/activity-element.html#dlmode">
    155 {@code android:documentLaunchMode}</a>.     ,    ,
    156      :</p>
    157 
    158 <dl>
    159   <dt>"{@code intoExisting}"</dt>
    160   <dd>      .   
    161  {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} <em></em> 
    162  {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK},    
    163 <a href="#flag-new-doc">  Intent   </a> .</dd>
    164 
    165   <dt>"{@code always}"</dt>
    166   <dd>     ,     . 
    167       {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT}
    168  {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK}.</dd>
    169 
    170   <dt>"{@code none}"</dt>
    171   <dd>      .   
    172     :        , 
    173     ,  .</dd>
    174 
    175   <dt>"{@code never}"</dt>
    176   <dd>      .   
    177    {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT}
    178   {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK},     
    179 intent,         , 
    180     ,  .</dd>
    181 </dl>
    182 
    183 <p class="note"><strong>.</strong>    {@code none}  {@code never}
    184       {@code launchMode="standard"}.     ,
    185  {@code documentLaunchMode="none"}.</p>
    186 
    187 <h2 id="removing"> </h2>
    188 
    189 <p>          
    190  .        {@link android.app.ActivityManager.AppTask},
    191   {@link android.content.Intent}   <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">
    192 &lt;activity&gt;</a></code>.</p>
    193 
    194 <p>         ,   
    195 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>
    196  <a href="{@docRoot}guide/topics/manifest/activity-element.html#exclude">
    197 {@code android:excludeFromRecents}</a>  {@code true}.</p>
    198 
    199 <p>    ,        ,   
    200 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>
    201  <a href="{@docRoot}guide/topics/manifest/activity-element.html#maxrecents">{@code android:maxRecents}
    202 </a>  .   : 16.      
    203        .   {@code android:maxRecents} 
    204 50 (25      );   1  .</p>
    205 
    206 <h3 id="#apptask-remove">  AppTask   </h3>
    207 
    208 <p> ,       ,
    209            , 
    210  {@link android.app.ActivityManager.AppTask#finishAndRemoveTask() finishAndRemoveTask()}.</p>
    211 
    212 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">
    213 NewDocumentActivity.java</a></p>
    214 <pre>
    215 public void onRemoveFromRecents(View view) {
    216     // The document is no longer needed; remove its task.
    217     finishAndRemoveTask();
    218 }
    219 </pre>
    220 
    221 <p class="note"><strong>.</strong> 
    222  {@link android.app.ActivityManager.AppTask#finishAndRemoveTask() finishAndRemoveTask()},
    223     {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS},
    224  .</p>
    225 
    226 <h3 id="#retain-finished">  </h3>
    227 
    228 <p>     ,     , 
    229  {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS}  
    230 {@link android.content.Intent#addFlags(int) addFlags()}  Intent,   .</p>
    231 
    232 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">
    233 DocumentCentricActivity.java</a></p>
    234 <pre>
    235 private Intent newDocumentIntent() {
    236     final Intent newDocumentIntent = new Intent(this, NewDocumentActivity.class);
    237     newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
    238       android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
    239     newDocumentIntent.putExtra(KEY_EXTRA_NEW_DOCUMENT_COUNTER, incrementAndGet());
    240     return newDocumentIntent;
    241 }
    242 </pre>
    243 
    244 <p>       
    245 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code>
    246  <a href="{@docRoot}guide/topics/manifest/activity-element.html#autoremrecents">
    247 {@code android:autoRemoveFromRecents}</a>  {@code false}.    {@code true}
    248     {@code false}   .    
    249  {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS},  .</p>
    250 
    251 
    252 
    253 
    254 
    255 
    256 
    257