rspec/rules/S3040/java/rule.adoc
2021-04-28 18:08:03 +02:00

45 lines
946 B
Plaintext

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++``
== 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
}
----
== Compliant Solution
----
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
doSomething();
}
public void onPostCreate(Bundle bundle) {
super.onPostCreate(bundle);
doSomethingElse();
}
----