java - React Native Android Intent putExtra obj ReadableMap 如何恢复对象
问题描述
我有以下代码:
ReadableMap infoIntent = frame.getMap("infoIntent");
Log.v("RN2: ", "/uri: " + infoIntent);
intent appIntent = new Intent(mReactContext, getCurrentActivity().getClass());
appIntent.setAction(ACTION_SHORTCUT);
appIntent.putExtra(SHORTCUT_ITEM, infoIntent);//(Parcelable) ??
我必须确保恢复这些数据并将其传递给承诺的人,所以我感觉是这样的:
@ReactMethod
@TargetApi(25)
public void popInitialAction(Promise promise) {
try {
Activity currentActivity = getCurrentActivity();
WritableMap map = null;
if (currentActivity != null) {
Intent intent = currentActivity.getIntent();
if (ACTION_SHORTCUT.equals(intent.getAction())) {
Parcelable bundle = intent.getParcelableExtra(SHORTCUT_ITEM);
Log.v("RN2: ", "/uri2: " + bundle);
/*if (bundle != null) {
map = item.toWritableMap();
}*/
}
}
promise.resolve(map);
} catch (Exception e) {
promise.reject(new JSApplicationIllegalArgumentException(
"AppShortcuts.popInitialAction error. " + e.getMessage()));
}
}
对象的类型是这样的:
infoIntent: {
name: "Megan",
surname: "Fox",
urlImg:
'https://scontent-mxp1-1.cdninstagram.com/vp/3c4732c2cd3566727dad10f03c04b7bd/5C9241C4/t51.2885-19/s150x150/34706107_1875460276079648_8096847319644766208_n.jpg',
age: 32,
height: "1.63 m"
}
对象的特性可能会有所不同,所以我不想创建一个带有 set 和 get 参数名称的类。
解决方案
推荐阅读
- arrays - 如何在 javaScript 中迭代这个 json 文件?
- json - 嵌套 SON 的列式 CSV 输出
- mule - 在 mule 4 中的响应负载中设置错误 http 状态
- excel - 如何使用 PowerShell 将文件内容写入 Excel 中的不同行
- postgresql - PostgreSQL中的全外连接,如果值不同且都不为空,则创建一个新行
- winforms - 为什么 Visual Studio 会自动更改控件位置和大小?
- python - 将变量传递给 zipfile NAME
- visual-studio-2017 - 更改 Visual Studio 2017 .props 位置文件
- windows - 如何将未分配的空间移动到不同的磁盘?(视窗)
- java - 泽西岛的多个路径参数