如何为android取消firebase setValue()的意图(How to cancel firebase setValue() intentionaly for android)
我已经读过这个问题它被问到swift但是我对android有一个完全相同的问题,这是如何在我想要programmaticaly时取消setValue()进程? 为了使问题更清楚,如果我在计时器完成时有进程的计时器,我希望它取消任何setValue()进程。
I have read this question it was asked for swift but I have an exact same question for android, which is how to cancel setValue() process when I want programmaticaly ? To make the question more clear if I have a timer for the process when timer completes I want it to cancel any setValue() process .
原文:https://stackoverflow.com/questions/46231555
最满意答案
您的帖子有相互矛盾的陈述:
1. how to access variable from a static class?
您的代码没有定义静态类,而是一个与ABC类同名的静态方法。
2. static method that has same name as class `ABC`.
如果您认为这是创建静态类的方式,那就错了。 静态类只能是外部类的内部。
3. tempabc = abc.
即使您定义了一个静态类,访问非静态变量也不是这样的。 除非变量也是静态的,否则您需要创建静态类的实例并以适当的方式访问变量值。
回答你发布的第二部分 :
您应该定义一个类来封装所述字段,如下所示:class HighestData { String names; int hours; int minutes; int seconds; int clicks; // define setter, getter methods or a constructor with input params for above fields. }
将方法从
void
更改return object of HighestData
。public static HighestData ReadHighestScoreFile() throws IOException { // your code here // ... HighestData data = new HighestData(); data.setName( name ); data.setHours( out.readInt() ); data.setMinutes( out.readInt() ); data.setSeconds( out.readInt() ); data.setClicks( out.readInt() ); // ... return data; }
ReadHighestScoreFile()
方法的调用者现在可以处理HighestData
对象并使用它进一步处理。最后但重要的是,与C不同,您无法在Java中定义本地静态字段。 他们必须在班级。
Your posting has conflicting statements:
1. how to access variable from a static class?
Your code does not have a static class defined but a static method with same name as class ABC.
2. static method that has same name as class `ABC`.
If you are thinking that it is the way creating a static class, it is wrong. Static classes can only be inner to Outer classes.
3. tempabc = abc.
Even if you define a static class, accessing non static variables is not in this way. Unless the variable too is a static, you require to create an instance of the static class and access the variable value in an appropriate way.
Answer to second part of your posting:
You should define a class to encapsulate the said fields as defined below:class HighestData { String names; int hours; int minutes; int seconds; int clicks; // define setter, getter methods or a constructor with input params for above fields. }
Change method from
void
toreturn object of HighestData
.public static HighestData ReadHighestScoreFile() throws IOException { // your code here // ... HighestData data = new HighestData(); data.setName( name ); data.setHours( out.readInt() ); data.setMinutes( out.readInt() ); data.setSeconds( out.readInt() ); data.setClicks( out.readInt() ); // ... return data; }
The caller of
ReadHighestScoreFile()
method can now have handle toHighestData
object and use it to process further.Lastly but important that, unlike in C, you can't define local static fields in Java. They must be at class level.
相关问答
更多-
您的帖子有相互矛盾的陈述: 1. how to access variable from a static class? 您的代码没有定义静态类,而是一个与ABC类同名的静态方法。 2. static method that has same name as class `ABC`. 如果您认为这是创建静态类的方式,那就错了。 静态类只能是外部类的内部。 3. tempabc = abc. 即使您定义了一个静态类,访问非静态变量也不是这样的。 除非变量也是静态的,否则您需要创建静态类的实例并以适当 ...
-
正确的尝试: 您可以将静 ...
-
您需要参考lvcontrol以便代码知道您要更新哪个(您可以打开两份表单!)。 如果lvcontrol是一个变量,那么在开始时就放弃这个 lvcontrol.Invoke(new Action(() => lvcontrol.Items.Add(item)) 如果不是你的代码要么都必须是非静态的,要么你需要传递一个对表单的引用(并且使用该引用而不是这个,例如,如果frm是对表单的引用 frm.lvcontrol.Invoke(new Action(() => frm.lvcontrol.Items.Add ...
-
您需要在变量之前包含类名称。 class MyClass { static var myArr = [String]() func getArr() -> [String] { return MyClass.myArr } } You need to include the class name before the variable. class MyClass { static var myArr = [String]() func ge ...
-
静态方法可以访问它知道的任何实例的非静态方法和字段。 但是,如果它不知道要在哪个实例上运行,则无法访问任何非静态的内容。 我认为你错在这样的例子不起作用: class Test { int x; public static doSthStatically() { x = 0; //doesn't work! } } 这里的静态方法不知道应该访问哪个Test实例。 相反,如果它是一个非静态方法,它会知道x引用this.x ( this在这里是隐含的),但是this不存在于静态上下文中。 ...
-
要访问实例变量,您需要使用实例。 只要您有需要,就不必在每次需要时创建它。 并为您的代码: if(first.getParentA().equals(second.getParentA())) 在这种情况下,您需要确保比first.getParentA()在比较之前不为null (否则您将获得NPE) In order to access instance variable, you need to use an instance. You don't have to create it each tim ...
-
你需要使它((A)b).x正确地输入它 注意:您正在尝试将属性x输入为A类型。 这是错误! You need to make it ((A)b).x to properly type cast it Note : You are trying to type cast the property x to type A. That's the error!
-
无法通过静态方法访问Mongoose中的Schema变量(Can't access Schema variables in Mongoose through static method)[2020-02-06]
自从我使用MongoDB(显然是Mongoose)以来,它已经有点了,但static方法无法访问实例。 因此,你真的不应该在静态方法中使用this 。 此外, BookInstanceSchema实例似乎没有属性the_statuses (只是虚拟statuses )。 从您的代码判断,看起来您可以访问BookInstanceSchema定义中的the_statuses变量。 那么,为什么不直接使用呢? BookInstanceSchema.statics.getStatuses = function() ... -
从实例访问它的简单方法是这样的...... public Color[] GetTextureData() { //note that `GameBot.` isn't required but I find it helpful to locate static //calls versus `this.` for instance methods return GameBot.GetTextureDataInternal(); } static intern ...
-
问题是,在您的可变pth被声明的那一刻,类“A”还不存在,因此评估失败。 如何宣布它? import os, platform class A(object): @staticmethod def getRoot(): return 'C:\\' if platform.system() == 'Windows' else '/' A.pth = os.path.join(A.getRoot(), 'some', 'path') 一个更丑陋的选择是: import os, ...