I created an abstract class to prevent redundant code in each of my activities.
public abstract class MyGeneralizedActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@Override
public void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
//...
}
I was perfectly fine by doing this:
public class MyActivity extends MyGeneralizedActivity{...}
But now I got to the point where I have to extend MyActivity
from FragmentActivity
. That means I can't extend from MyGeneralizedActivity
anymore.
Now I am wondering if it's possible to set up a general abstract structure to extend all of my activities.
EDIT
Just by extending MyGeneralizedActivity
from FragmentActivity
won't solve my problem. e.g. TabActivity
will lead to the same issue.
UPDATE
For those who may be interested in solving the same problem in Android I've found a simple workaround. There exist the Application class, which provides, among other things, the interface ActivityLifecycleCallbacks. It does exactly what I need allowing us to intercept and add some value into important events for all activities.
All you have to do is to extend the Android Application
Class and create a private class within which implements ActivityLifecycleCallbacks
.
Don't forget to add/rename your Application in your AndroidManifests
file:
<application
android:name=".application.MyApplication"
//...
/>