rspec/rules/S3040/java/rule.adoc

52 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
In certain Android methods, calls to the ``++super++`` version of the method should always come first. Otherwise, you risk leaving the job half-done.
This rule raises an issue when the following ``++Activity++`` methods do not begin with a call to ``++super++``:
* ``++onCreate++``
* ``++onConfigurationChanged++``
* ``++onPostCreate++``
* ``++onPostResume++``
* ``++onRestart++``
* ``++onRestoreInstanceState++``
* ``++onResume++``
* ``++onStart++``
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
public void onCreate(Bundle bundle) { // Noncompliant; super call missing
doSomething();
}
public void onPostCreate(Bundle bundle) {
doSomethingElse();
super.onPostCreate(bundle); // Noncompliant; should be first statement
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
doSomething();
}
public void onPostCreate(Bundle bundle) {
super.onPostCreate(bundle);
doSomethingElse();
}
----
ifdef::env-github,rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]