Android Studio 怎么知道显示“Toast 创建但未显示:您是否忘记调用 show()?"?警告? [英] How does Android Studio know to display the "Toast created but not shown: did you forget to call show()?" warning?
问题描述
当您创建 Toast 但不调用 show()
方法时,Android Studio 会显示一个工具提示:Toast 已创建但未显示:您是否忘记调用 show()?"另一个示例是在将值放入 SharedPreferencesEditor
对象并显示工具提示时不调用 commit
或 apply
.
When you create a Toast but do not call the show()
method Android Studio shows an tooltip saying: "Toast created but not shown: did you forget to call show()?" another example is not calling commit
or apply
when putting values into a SharedPreferencesEditor
object and a tooltip being displayed.
这只是 Android Studio 有用吗,还是有一种方法可以定义在调用一个方法后应该调用另一个方法?
Is this just Android Studio being helpful or is there a way to define that after a method is called another method should be called?
推荐答案
这只是 Intellij (Android Studio) 足够聪明,可以通过静态代码分析进行计算.
This is just Intellij (Android Studio) being smart enough to figure through static code analysis.
没有办法告诉编译器在这样的方法之后应该运行另一个方法.最接近它的是编写单元测试,即使它只在测试运行期间通知您.
There is no way to tell the compiler that after such method another method should run. The closest thing to it is writing unit tests and even that only notifies you during your test runs.
这篇关于Android Studio 怎么知道显示“Toast 创建但未显示:您是否忘记调用 show()?"?警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!