Android DocumentCentricRelinquishIdentity Sample
This sample shows how to relinquish identity to activities above it in the task stack.
此示例演示如何修改掉Activitys的身份标示,然后把它放入到任务堆栈活动中。
<activity
android:name=".RelinquishIdentityActivity"
android:label="@string/activity_relinquish_title"
android:relinquishTaskIdentity="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
关于其中的android:relinquishTaskIdentity这个属性,我真的不了解,下面是这个属性的说明:
Tasks whose root has this attribute set to true will replace baseIntent with that of the next activity in the task. If the next activity also has this attribute set to true then it will yield the baseIntent to any activity that it launches in the same task.
This continues until an activity is encountered which has this attribute set to false. False is the default. This attribute set to true also permits activity's use of the TaskDescription to change labels, colors and icons in the recent task list.
任务的根具有此属性设置为 true 将替换 baseIntent,该任务的下一个活动。如果下一个活动也具有此属性设置为 true,则它会屈服于任何活动 baseIntent,它将启动相同的任务。这样下去直到活动遇到具有此属性设置为 false。假的是默认的。此属性设置为 true,也允许活动的使用的 TaskDescription 更改标签、 颜色和最近的任务列表中的图标。
我把这个设置为false,效果也和设置成true是一样,暂时还是不太理解。
这次,还是没有多少要说的,主要是新的api使用。
第一个Activity:
public class RelinquishIdentityActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_relinquish_identity);
}
public void createNewDocument(View view) {
final Intent intent = newDocumentIntent();
startActivity(intent);
}
/**
* Returns an new intent to start {@link NewDocumentActivity}
* as a new document in recents..
*///因为设置了下面的属性,所以新的Activity出现在新的task中
private Intent newDocumentIntent() {
final Intent newDocumentIntent = new Intent(this, NewDocumentActivity.class);
newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
// Always launch in a new task.
newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
return newDocumentIntent;
}
}
第二个Activity:public class NewDocumentActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_document);
// Set a new task description to change label and icon
setTaskDescription(newTaskDescription());
}
/**
* Creates a new {@link android.app.ActivityManager.TaskDescription} with a new label and icon to change the
* appearance of this activity in the recents stack.
*/设置关于本Activity的task说明,图标和文字
private ActivityManager.TaskDescription newTaskDescription() {
Bitmap newIcon = BitmapFactory.decodeResource(getResources(), R.drawable.new_icon);
String newDocumentRecentsLabel = getString(R.string.new_document_recents_label);
ActivityManager.TaskDescription newTaskDescription = new ActivityManager.TaskDescription(
newDocumentRecentsLabel, newIcon);
return newTaskDescription;
}
}
截图:需要按home退出,然后在进程列表中看出,