Merge "Add NEW_TASK flag to intent if metadata matches"

This commit is contained in:
TreeHugger Robot
2022-02-14 10:24:56 +00:00
committed by Android (Google) Code Review
3 changed files with 11 additions and 8 deletions

View File

@@ -35,8 +35,7 @@ public class ActivityTile extends Tile {
private static final String TAG = "ActivityTile";
public ActivityTile(ActivityInfo info, String category) {
super(info, category);
setMetaData(info.metaData);
super(info, category, info.metaData);
}
ActivityTile(Parcel in) {

View File

@@ -43,8 +43,7 @@ public class ProviderTile extends Tile {
private String mKey;
public ProviderTile(ProviderInfo info, String category, Bundle metaData) {
super(info, category);
setMetaData(metaData);
super(info, category, metaData);
mAuthority = info.authority;
mKey = metaData.getString(META_DATA_PREFERENCE_KEYHINT);
}

View File

@@ -71,16 +71,19 @@ public abstract class Tile implements Parcelable {
private Bundle mMetaData;
private String mCategory;
public Tile(ComponentInfo info, String category) {
public Tile(ComponentInfo info, String category, Bundle metaData) {
mComponentInfo = info;
mComponentPackage = mComponentInfo.packageName;
mComponentName = mComponentInfo.name;
mCategory = category;
mMetaData = metaData;
mIntent = new Intent().setClassName(mComponentPackage, mComponentName);
if (isNewTask()) {
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
}
Tile(Parcel in) {
final boolean isProviderTile = in.readBoolean();
mComponentPackage = in.readString();
mComponentName = in.readString();
mIntent = new Intent().setClassName(mComponentPackage, mComponentName);
@@ -90,6 +93,9 @@ public abstract class Tile implements Parcelable {
}
mCategory = in.readString();
mMetaData = in.readBundle();
if (isNewTask()) {
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
}
@Override
@@ -332,8 +338,7 @@ public abstract class Tile implements Parcelable {
/**
* Whether the {@link Activity} should be launched in a separate task.
*/
public boolean isNewTask(Context context) {
ensureMetadataNotStale(context);
public boolean isNewTask() {
if (mMetaData != null
&& mMetaData.containsKey(META_DATA_NEW_TASK)) {
return mMetaData.getBoolean(META_DATA_NEW_TASK);