【发布时间】:2014-06-24 10:48:16
【问题描述】:
我打算像这样开始一个快捷方式活动:
startActivity((Intent) shortcut_intent.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT));
我需要将shortcut_intent 转换为字符串以将其保存在sqlite db 中。我尝试了这么久,但没有成功。目前我站在这里:
将意图转换为字符串:
String uri_string = mIntent_shortcut_intent.toUri(0);
创建新意图:
Intent intent = new Intent();
并从 uri 解析额外内容:
intent.putExtra("android.intent.extra.shortcut.INTENT", Uri.parse(uri_string));
无法正常工作/应用程序崩溃了;(
有人可以帮我解决这个问题吗?或者告诉我在 sqlite db 中持久保存意图的替代方法?
提前谢谢
更新:
正如 pskink 建议的那样,解组额外捆绑包,反之亦然,我做了以下操作:
Bundle bundle=shortcutIntent.getExtras();
Parcel parcel=Parcel.obtain();
bundle.writeToParcel(parcel, 0);
byte[] byt=parcel.marshall();
Bundle newBundle=new Bundle();
Parcel newParcel=Parcel.obtain();
newParcel.unmarshall(byt, 0, byt.length);
bundle.readFromParcel(newParcel);
Intent intent=new Intent();
intent.putExtras(newBundle);
startActivity((Intent) intent.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT));
newBundle 看起来与原始捆绑包不完全相同,并且它仍在崩溃。所以还是有问题.....
【问题讨论】:
-
你能发布日志堆栈吗?
-
使用
String action=intent.getAction();并将其存储到sqlite。 -
@Ketan Ahir:在我的快捷方式中,Action 始终为“null”。只有“Extras”才有价值,所以我认为它没用......
-
使用此构造函数创建意图 Intent i=new Intent("your action");
-
意图意图 = Intent.parse(uri_string)
标签: java android sqlite android-intent