首页 > 解决方案 > 如何在主函数中获取“OnSuccessListener()”的输出

问题描述

interpreter.run(inputs, inputOutputOptions)
                .addOnSuccessListener(
                        new OnSuccessListener<FirebaseModelOutputs>() {
                            @Override
                            public void onSuccess(FirebaseModelOutputs result) {
                                String str;
                                float[][] output = result.getOutput(0);
                               float[] probabilities = output[0];
                                float res=probabilities[0];
                                //Log.d(TAG, "onSuccess res: "+result.getOutput(0).toString());
                                System.out.println(output[0][0]);
                                System.out.println(output[0][1]);
                                if (output[0][0]>output[0][1]){
                                  //till here my code is properly Running
                                    str="Class1";
                                  graphicOverlay.add(new FaceGraphic(graphicOverlay, face,str));
                                //But when i try to call this method this method not getting called same for else case

                                }
                                else {
                               //till here my code is properly Running
                                    str="Class2";
                                }
                            }
                        })
                .addOnFailureListener(
                        new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {

                            }
                        });

如何在我的主要方法中获取变量“str”的值?
我尝试将字符串声明为静态类,但它给出了最后存储的输出(str 的值不会随着它的变化而更新)
谢谢你提前

标签: javaandroidfirebase

解决方案


推荐阅读