简体   繁体   English

如果 function 已正确运行,则返回 true

[英]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.

相关问题 递归 function 有一个整数数组,它的大小作为参数,如果数组元素的总和是偶数,它将返回 true? - Recursive function that has an array of integers and it's size as parameters that will return true if the sum of the array elements is even? 如果 hasNextInt() 什么都没有,扫描器 hasNextInt() 返回 true - Scanner hasNextInt() return true if hasNextInt() has nothing 当函数没有返回值时,Delphi XE2是否可以从Java / Axis2正确导入WSDL? - Does Delphi XE2 correctly import WSDL from Java/Axis2 when function has no return value? 函数不能正确返回数字 - function does not return number correctly 如果线程失败,函数必须返回真 - Function must return true if thread fails 尽管返回条件为真,函数也不会返回 - function wont return despite condition of the return being true 对于具有私有构造函数的类,instanceof如何返回true? - How can instanceof return true for a class that has a private constructor? 迭代器有项目但 hasnext 不返回 true - iterator has item but hasnext doesn't return true 如果条件为true,则if语句中的函数不执行且应用程序已停止工作 - If condition is true, the function in if statement not execute and the application has stopped working Function 总是返回false,连buffer都是true值? - Function always return false, even the buffer is true value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM