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 18:08:03 +02:00
|
|
|
|
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 18:08:03 +02:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
----
|
2021-04-28 18:08:03 +02:00
|
|
|
|
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::comments-and-links.adoc[]
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|