I’m trying to override a class derived from Activity (called NativeActivity) so I can set my own content view created in Java while leaving the rest of its functionality in tact. I must use NativeActivity, because it is the only way to get touchpad input on Xperia Play. The method I need to override is the NativeActivity.onCreate() method, because that is where the content view that I don’t want is being set. The problem is, if I don’t call super.onCreate() in my overridden onCreate() method, a SuperNotCalledException gets thrown. This is coming from the Activity class. But all the Activity.onCreate() method does is set a boolean:
protected void onCreate(Bundle savedInstanceState) {
mVisibleFromClient = !mWindow
.getWindowStyle()
.getBoolean(
com.android.internal.R.styleable.Window_windowNoDisplay,
false);
mCalled = true;
}
I can do that check in my own code, using the Activity.getWindow() method. Unfortunately, the mCalled boolean is private, so I can’t just set it to true in my own code. I can’t seem to figure out how to get around this requirement. Any ideas?
One thing I figured out from studying the sourcecode for Activity, is you could call one of the methods that set mCalled to true in the base Activity clase, which are not overridden in the subclass, and which do nothing in the base Activity class. So in the case of NativeActivty, one could call something like
super.onRestart();, because this class is not overridden by NativeActivity, and as you can see below, it doesn’t do anything in the Activity class:This is quite hackish, and could be broken at some future version, but can be a quick solution if you don’t want to have to recreate an entire subclass of Activity just because of one simple boolean.