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"></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><a href="{@docRoot}guide/components/activities.html"></a><a href="{@docRoot}guide/components/tasks-and-back-stack.html"></a> UI 40 41 42 43 Android 5.0API 211 44 Google Google 45 1 46 </p> 47 48 <img src="{@docRoot}images/components/recents.png" alt="" width="284" /> 49 <p class="img-caption"><strong> 1.</strong> 3 Google 50 </p> 51 52 <p> 53 54 {@link android.app.ActivityManager.AppTask} {@link android.content.Intent} 55 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 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> 64 65 66 </p> 67 68 <h3 id="flag-new-doc"> </h3> 69 70 <p>{@link android.app.ActivityManager.AppTask} {@link android.app.ActivityManager.AppTask#startActivity(android.content.Context, android.content.Intent, android.os.Bundle) startActivity()} 71 72 73 {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} {@link android.content.Intent} {@link android.content.Intent#addFlags(int) addFlags()} 74 75 76 </p> 77 78 <p class="note"><strong>:</strong> {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} Android 5.1API 21 {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET} 79 80 </p> 81 82 <p> {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} 83 84 s 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} {@code android:launchMode="standard"} 114 115 </p> 116 117 <p> 118 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} 119 120 {@link android.app.Activity#onNewIntent onNewIntent()} 121 122 123 </p> 124 125 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html"> 126 NewDocumentActivity.java</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"></h3> 151 152 <p><code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#dlmode">{@code android:documentLaunchMode}</a> 153 154 155 4 156 </p> 157 158 <dl> 159 <dt>{@code intoExisting}</dt> 160 <dd><a href="#flag-new-doc"> </a>{@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} <em></em>{@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} 161 162 163 </dd> 164 165 <dt>{@code always}</dt> 166 <dd>{@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> 1 172 173 </dd> 174 175 <dt>{@code never}</dt> 176 <dd>{@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} 1 177 178 179 180 </dd> 181 </dl> 182 183 <p class="note"><strong>:</strong> {@code none} {@code never} {@code launchMode="standard"} 184 {@code documentLaunchMode="none"} 185 </p> 186 187 <h2 id="removing"></h2> 188 189 <p> 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><code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#exclude">{@code android:excludeFromRecents}</a> {@code true} 195 196 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 251 204 </p> 205 206 <h3 id="#apptask-remove">AppTask </h3> 207 208 <p> {@link android.app.ActivityManager.AppTask#finishAndRemoveTask() finishAndRemoveTask()} 209 210 </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> {@link android.app.ActivityManager.AppTask#finishAndRemoveTask() finishAndRemoveTask()} {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS} 222 223 224 </p> 225 226 <h3 id="#retain-finished"></h3> 227 228 <p>{@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS} {@link android.content.Intent#addFlags(int) addFlags()} 229 230 </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><code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> <a href="{@docRoot}guide/topics/manifest/activity-element.html#autoremrecents">{@code android:autoRemoveFromRecents}</a> {@code false} 245 246 247 {@code true} {@code false} 248 {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS} 249 </p> 250 251 252 253 254 255 256 257