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"> 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> 40 UI<a href="{@docRoot}guide/components/activities.html">Activity</a><a href="{@docRoot}guide/components/tasks-and-back-stack.html"></a> 41 42 43 44 Android 5.0 API 21 Activity Google Drive 45 Google 46 </p> 47 48 <img src="{@docRoot}images/components/recents.png" alt="" width="284" /> 49 <p class="img-caption"><strong> 1. </strong> 50 Google Drive </p> 51 52 <p> Activity Activity 53 54 {@link android.app.ActivityManager.AppTask} 55 56 {@link android.content.Intent} 57 Activity Activity <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"> Intent </h3> 69 70 <p> Activity 71 {@link android.app.ActivityManager.AppTask} 72 {@link android.app.ActivityManager.AppTask#startActivity(android.content.Context, android.content.Intent, android.os.Bundle) startActivity()} 73 Activity Intent Activity Activity 74 {@link android.content.Intent} 75 {@link android.content.Intent#addFlags(int) addFlags()} {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} 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.0API 21</p> 81 82 <p> 83 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} 84 Activity Activity 85 </p> 86 87 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">DocumentCentricActivity.java</a> 88 </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 Activity {@code android:launchMode="standard"} 115 </p> 116 117 <p> Activity Activity Intent Activity Intent Intent 118 Intent 119 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} 120 Activity 121 Intent 122 123 {@link android.app.Activity#onNewIntent onNewIntent()} Activity Intent </p> 124 125 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">NewDocumentActivity.java</a> 126 </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 153 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></a></code> 154 <a href="{@docRoot}guide/topics/manifest/activity-element.html#dlmode">{@code android:documentLaunchMode}</a> 155 156 </p> 157 158 <dl> 159 <dt>{@code intoExisting}</dt> 160 <dd> Activity 161 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} 162 163 {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} <a href="#flag-new-doc"> Intent </a><em></em></dd> 164 165 <dt>{@code always}</dt> 166 <dd> Activity 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> Activity Activity Activity 172 173 </dd> 174 175 <dt>{@code never}</dt> 176 <dd> Activity 177 {@link android.content.Intent#FLAG_ACTIVITY_NEW_DOCUMENT} 178 {@link android.content.Intent#FLAG_ACTIVITY_MULTIPLE_TASK} 179 Intent 180 Activity </dd> 181 </dl> 182 183 <p class="note"><strong></strong> {@code none} {@code never} 184 {@code launchMode="standard"} Activity 185 {@code documentLaunchMode="none"}</p> 186 187 <h2 id="removing"></h2> 188 189 <p> Activity 190 {@link android.app.ActivityManager.AppTask} 191 {@link android.content.Intent} <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"> 192 <activity></a></code> </p> 193 194 <p> 195 <code><a href="{@docRoot}guide/topics/manifest/activity-element.html"><activity></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"><activity></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> Activity 209 {@link android.app.ActivityManager.AppTask#finishAndRemoveTask() finishAndRemoveTask()} 210 Activity</p> 211 212 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">NewDocumentActivity.java</a> 213 </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> Activity Activity 229 Intent {@link android.content.Intent#addFlags(int) addFlags()} 230 {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS} </p> 231 232 <p class="code-caption"><a href="{@docRoot}samples/DocumentCentricApps/index.html">DocumentCentricActivity.java</a> 233 </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> 246 <a href="{@docRoot}guide/topics/manifest/activity-element.html#autoremrecents"> 247 {@code android:autoRemoveFromRecents}</a> {@code false} Activity 248 {@code true} Activity {@code false} 249 {@link android.content.Intent#FLAG_ACTIVITY_RETAIN_IN_RECENTS} </p> 250 251 252 253 254 255 256 257