牛轧糖版本的快捷方式
Shortcuts for Nougat version
当我尝试在 Intent 包中传递一个 Serializable 时,我捕获了这个致命异常,我认为这与我试图实现的牛轧糖快捷方式有关。这里是例外:
12-16 16:17:32.972 20461-20461/***.****.******.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: ***.****.******.debug, PID: 20461
java.lang.IllegalArgumentException: Bad value in PersistableBundle key=shortcutId value=***.****.******.common.cta.CtaAccountSectionModel@1fb70dc
at android.os.PersistableBundle.<init>(PersistableBundle.java:124)
at android.os.PersistableBundle.<init>(PersistableBundle.java:98)
at android.content.pm.ShortcutInfo.fixUpIntentExtras(ShortcutInfo.java:267)
at android.content.pm.ShortcutInfo.<init>(ShortcutInfo.java:245)
at android.content.pm.ShortcutInfo.<init>(ShortcutInfo.java)
at android.content.pm.ShortcutInfo$Builder.build(ShortcutInfo.java:1027)
at ****.******.***.ShortcutHelper.createShortcut(ShortcutHelper.java:79)
at ****.******.***.ShortcutHelper.refreshShortcuts(ShortcutHelper.java:87)
at ****.******.***.****.******.***.refreshShortcuts(Application.java:93)
at ****.******.***.refreshShortcuts(SettingActivity.java:247)
at ****.******.***.storeShortcuts(SettingActivity.java:242)
at c****.******.***.access0(SettingActivity.java:56)
at ****.******.***.SettingActivity.onClick(SettingActivity.java:233)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
CtaAccountSectionModel.class
public class CtaAccountSectionModel extends CtaModel implements Serializable {
}
CtaModel.class
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
defaultImpl = CtaDefaultModel.class,
property = "action", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = CtaProductPageModel.class, name = CtaActionModel.ACTION_PRODUCT_PAGE))})
public class CtaModel implements Serializable {
private String action;
private String name;
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
这里是我创建意图的代码:
public ShortcutBackStackBuilder getHistoryWithBackStack(String section) {
Intent intent = IntentAppFactory.createMainActivityFromShortcut(mContext).putExtra(IntentExtraConstants.EXTRA_SHORTCUT_ID, new CtaAccountSectionModel(section))
.setAction(Intent.ACTION_MAIN);
mIntentLinkedList.add(intent);
return this;
}
有人知道是否不允许在牛轧糖快捷方式中传递 Serializable 吗?
PersistableBundle class 使用以下方法检查其内容:
public static boolean isValidType(Object value) {
return (value instanceof Integer) || (value instanceof Long) ||
(value instanceof Double) || (value instanceof String) ||
(value instanceof int[]) || (value instanceof long[]) ||
(value instanceof double[]) || (value instanceof String[]) ||
(value instanceof PersistableBundle) || (value == null) ||
(value instanceof Boolean) || (value instanceof boolean[]);
}
很遗憾,只有这些 classes 可以捆绑到 Intent for Shortcuts 中。
当我尝试在 Intent 包中传递一个 Serializable 时,我捕获了这个致命异常,我认为这与我试图实现的牛轧糖快捷方式有关。这里是例外:
12-16 16:17:32.972 20461-20461/***.****.******.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: ***.****.******.debug, PID: 20461
java.lang.IllegalArgumentException: Bad value in PersistableBundle key=shortcutId value=***.****.******.common.cta.CtaAccountSectionModel@1fb70dc
at android.os.PersistableBundle.<init>(PersistableBundle.java:124)
at android.os.PersistableBundle.<init>(PersistableBundle.java:98)
at android.content.pm.ShortcutInfo.fixUpIntentExtras(ShortcutInfo.java:267)
at android.content.pm.ShortcutInfo.<init>(ShortcutInfo.java:245)
at android.content.pm.ShortcutInfo.<init>(ShortcutInfo.java)
at android.content.pm.ShortcutInfo$Builder.build(ShortcutInfo.java:1027)
at ****.******.***.ShortcutHelper.createShortcut(ShortcutHelper.java:79)
at ****.******.***.ShortcutHelper.refreshShortcuts(ShortcutHelper.java:87)
at ****.******.***.****.******.***.refreshShortcuts(Application.java:93)
at ****.******.***.refreshShortcuts(SettingActivity.java:247)
at ****.******.***.storeShortcuts(SettingActivity.java:242)
at c****.******.***.access0(SettingActivity.java:56)
at ****.******.***.SettingActivity.onClick(SettingActivity.java:233)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
CtaAccountSectionModel.class
public class CtaAccountSectionModel extends CtaModel implements Serializable {
}
CtaModel.class
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
defaultImpl = CtaDefaultModel.class,
property = "action", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = CtaProductPageModel.class, name = CtaActionModel.ACTION_PRODUCT_PAGE))})
public class CtaModel implements Serializable {
private String action;
private String name;
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
这里是我创建意图的代码:
public ShortcutBackStackBuilder getHistoryWithBackStack(String section) {
Intent intent = IntentAppFactory.createMainActivityFromShortcut(mContext).putExtra(IntentExtraConstants.EXTRA_SHORTCUT_ID, new CtaAccountSectionModel(section))
.setAction(Intent.ACTION_MAIN);
mIntentLinkedList.add(intent);
return this;
}
有人知道是否不允许在牛轧糖快捷方式中传递 Serializable 吗?
PersistableBundle class 使用以下方法检查其内容:
public static boolean isValidType(Object value) {
return (value instanceof Integer) || (value instanceof Long) ||
(value instanceof Double) || (value instanceof String) ||
(value instanceof int[]) || (value instanceof long[]) ||
(value instanceof double[]) || (value instanceof String[]) ||
(value instanceof PersistableBundle) || (value == null) ||
(value instanceof Boolean) || (value instanceof boolean[]);
}
很遗憾,只有这些 classes 可以捆绑到 Intent for Shortcuts 中。