I have extended AppCompatActivity and onCreate showing red highlight
Using Android Studio 1.3 Preview
I have implemented AppCompatActivity
everything works, but it onCreate
shows an underline and then after mouse over it shows an error
the overriding method should call super.onCreate ();
There is a super challenge though.
Why is it showing red backlight?
source to share
Update: This issue is fixed in Android Studio 1.3 preview 2
This is a known issue with the Android Studio 1.3 preview design . It reports false positives with a Lint check.
You can read about the problem here:
https://code.google.com/p/android/issues/detail?id=174964
You can go to the newest android studio in the release channel (1.2) or the suggested fix:
You can temporarily cancel "Lint Inspections".
In Android Studio 1.3: Android Studio> Settings> Inspections> Android Lint> Missing supercall
source to share
I just ran into this same issue with Android Studio 2.3.2 stable.
My situation was in a class that extended another class, I wrote that extended AppCompatActivity. I actually went to the first super.on Created both the savedStatus Information and layout, and that one called it super.onCreate as expected.
It was weird that out of 20 or so classes with this template, only one got a lint error.
This is how my classes were implemented:
public class MyActivity extends BaseNavActivity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.activity_locations);
// stuff
}
}
and
abstract class BaseNavActivity extends AppCompatActivity {
...
protected void onCreate(Bundle savedInstanceState, int resLayout) {
// need to set the theme first
setTheme(R.style.AppTheme2);
// then call super before setting the content view
super.onCreate(savedInstanceState);
setContentView(resLayout);
// stuff
}
}
I solved this the same way as the original answer by going to (on Mac OS X) Android Studio> Preferences> Editor> Checks and changing the "Missing supercall" rule to just be a warning.
(Hopefully this is just a bug, not something I am doing wrong and will be fixed soon, and I can change this warning to an error, as this is usually a useful check.)
source to share