[英]Return true if a function has ran correctly
so I have a functions called Single<List<Settings>> runUpgrade(Context context)
in a class called UpgradeHelper
where Single is imported from import io.reactivex.Single
.所以我在名为
UpgradeHelper
的 class 中有一个名为Single<List<Settings>> runUpgrade(Context context)
的函数,其中 Single 是从import io.reactivex.Single
的。 I need to check in my ContentProvider
if the runUpgrade(Context context)
method was successful in executing the upgrade and return true
if it was otherwise return false
.如果
runUpgrade(Context context)
方法成功执行升级,我需要检查我的ContentProvider
,否则返回true
,否则返回false
。
I have created another boolean function called boolean checkUpgradeSuccess()
but I am confused as to how I can check for the success of the upgrade?我创建了另一个名为
boolean checkUpgradeSuccess()
但我对如何检查升级是否成功感到困惑?
My code for the checkUpgradeSuccess()
is as follows so far, but I don't know how to move forward:到目前为止,我的
checkUpgradeSuccess()
代码如下,但我不知道如何继续:
private boolean checkMigrationSuccess(){
UpgradeHelper uHelper = new UpgradeHelper();
uHelper.runUpgrade(getContext());
return true;
}
Any help or advice will be highly appreciated.任何帮助或建议将不胜感激。
runUpgrade method should return result info such as success, error etc about upgrade status. runUpgrade 方法应返回有关升级状态的结果信息,例如成功、错误等。 Also i highly recommend to separate the methods as migrate and checkStatus because you may need to check the status many times after migration.
此外,我强烈建议将方法分离为 migrate 和 checkStatus ,因为您可能需要在迁移后多次检查状态。
private isSuccess:Boolean = false;
private boolean migrate(){
UpgradeHelper uHelper = new UpgradeHelper();
isSuccess = uHelper.runUpgrade(getContext());
}
private boolean checkStatus(){
return isSuccess;
}
How about working with exceptions?如何处理异常? Create your own xxxExcption and put your code in
创建您自己的 xxxExcption 并将您的代码放入
try {
...
} catch (Exception e) {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.