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"></a></li> 14 <li><a href="#attr-doclaunch"> Activity </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> () UI <a href="{@docRoot}guide/components/activities.html">Activity</a> <a href="{@docRoot}guide/components/tasks-and-back-stack.html"></a> 40 41 42 43 Android 5.0 (API 21) Activity () 44 Google Google 45 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> Activity 53 Activity 54 55 {@link android.app.ActivityManager.AppTask} {@link android.content.Intent} Activity Activity 56 57 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"> 58 <activity></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"><activity></a></code> 65 66 </p> 67 68 <h3 id="flag-new-doc"></h3> 69 70 <p> Activity 71 {@link android.app.ActivityManager.AppTask} {@link android.app.ActivityManager.AppTask#startActivity(android.content.Context, android.content.Intent, android.os.Bundle) startActivity()} Activity 72 73 Activity Activity {@link android.content.Intent} {@link android.content.Intent#addFlags(int) addFlags()} {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} 74 75 76 </p> 77 78 <p class="note"><strong></strong>{@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET} Android 5.0 (API 21) 79 80 </p> 81 82 <p> {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} Activity 83 84 Activity 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} Activity {@code android:launchMode="standard"} () 114 115 </p> 116 117 <p> Activity Activity Activity Activity 118 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} Activity 119 120 {@link android.app.Activity#onNewIntent onNewIntent()} 121 Activity 122 123 </p> 124 125 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">NewDocumentActivity.java 126 </a></p> 127 <pre> 128 @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 @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"> Activity </h3> 151 152 <p>Activity <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#dlmode"> 153 {@code android:documentLaunchMode}</a> 154 155 156 </p> 157 158 <dl> 159 <dt>"{@code intoExisting}"</dt> 160 <dd>Activity 161 {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} <em></em> 162 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} <a href="#flag-new-doc"></a> 163 </dd> 164 165 <dt>"{@code always}"</dt> 166 <dd>Activity {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} 167 168 </dd> 169 170 <dt>"{@code none}"</dt> 171 <dd>Activity Activity Activity 172 173 </dd> 174 175 <dt>"{@code never}"</dt> 176 <dd>Activity {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} Activity 177 178 179 180 </dd> 181 </dl> 182 183 <p class="note"><strong></strong> {@code none} {@code never} Activity {@code launchMode="standard"} 184 185 {@code documentLaunchMode="none"}</p> 186 187 <h2 id="removing"></h2> 188 189 <p> Activity 190 {@link android.app.ActivityManager.AppTask} {@link android.content.Intent} <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"> 191 <activity></a></code> 192 </p> 193 194 <p> 195 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#exclude"> 196 {@code android:excludeFromRecents}</a> {@code true} 197 </p> 198 199 <p> <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#maxrecents">{@code android:maxRecents}</a> 200 201 202 16 203 {@code android:maxRecents} 50 ( 25) 1 204 </p> 205 206 <h3 id="#apptask-remove"> AppTask </h3> 207 208 <p> Activity Activity{@link android.app.ActivityManager.AppTask#finishAndRemoveTask() finishAndRemoveTask()} 209 210 </p> 211 212 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">NewDocumentActivity.java 213 </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()} {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS} 223 224 </p> 225 226 <h3 id="#retain-finished"></h3> 227 228 <p> ( Activity ) Activity {@link android.content.Intent#addFlags(int) addFlags()} 229 {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS} 230 </p> 231 232 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">DocumentCentricActivity.java 233 </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"><activity></a></code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#autoremrecents"> 246 {@code android:autoRemoveFromRecents}</a> {@code false} 247 Activity {@code true} Activity {@code false} 248 {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS} 249 </p> 250 251 252 253 254 255 256 257