小编Ehs*_*san的帖子

如何将sparsearray存储在bundle中

我有一个SparseArray<myObject>并希望将它存储onSaveInstanceState在我的活动中的方法包中并将其恢复oncreate.我找到putSparseParcelableArray了将SparseArray放入bundle中的onSaveInstanceState方法,并在方法中执行了此操作:

bundle.putSparseParcelableArray("mySparseArray", mySparseArray);
Run Code Online (Sandbox Code Playgroud)

但是eclips显示了这个错误:

The method putSparseParcelableArray(String, SparseArray<? extends Parcelable>) in the type Bundle is not applicable for the arguments (String, SparseArray<myObject>)
Run Code Online (Sandbox Code Playgroud)

快速解决方法是将参数转换mySparsArraySparseArray<? extends Parcelable>,但如果我这样做并在onCreate方法中获取它:

mySparseArray = (SparseArray<myObject>) savedInstanceState.getSparseParcelableArray("mySparseArray");
Run Code Online (Sandbox Code Playgroud)

它收到此错误:

Cannot cast from SparseArray<Parcelable> to SparseArray<myObject>
Run Code Online (Sandbox Code Playgroud)

如果这种方式出错了,将mySparseArray放入bundle中的解决方案是什么?任何帮助将非常感激.

android bundle sparse-array android-activity

5
推荐指数
2
解决办法
8989
查看次数

如何在bash脚本中获取nohup proccess id

我有一个bash脚本通过nohup运行命令,我需要脚本中的proccess id.

我试过这个:

#!/bin/bash
nohupResult=$((nohup mycommand > nohup.out &) 2>&1)
echo $nohupResult
exit 0
Run Code Online (Sandbox Code Playgroud)

但是$nohupResult没有.

我也尝试了这个:

nohupResult=`nohup mycommand > nohup.out &`
Run Code Online (Sandbox Code Playgroud)

但是$nohupResult也是无效的.

如果我nohup mycommand > nohup.out &在shell中运行命令,我会得到一些输出,如:

[1] 447019
Run Code Online (Sandbox Code Playgroud)

但是我如何在脚本中获取进程ID?

任何帮助将非常感激.

bash process nohup

2
推荐指数
1
解决办法
1357
查看次数

标签 统计

android ×1

android-activity ×1

bash ×1

bundle ×1

nohup ×1

process ×1

sparse-array ×1