Skip to content

ActivityExtendExample

pedroduran edited this page Jul 25, 2013 · 1 revision

Using ActionBarSherlock or a similar library

If you use a library that already requires your activities to extend a base class (e.g. ActionBarSherlock), simply create your own base activity using MalcomLifecycleDispatchActivity.java as a starting point. Here is an example for the ActionBarSherlock library:

    public class MyBaseActivity extends SherlockFragmentActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if (MalcomApplicationHelper.PRE_ICS) MalcomMainLifecycleDispatcher.get().onActivityCreated(this, savedInstanceState);
        }
    
        @Override
        protected void onStart() {
            super.onStart();
            if (MalcomApplicationHelper.PRE_ICS) MalcomMainLifecycleDispatcher.get().onActivityStarted(this);
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            if (MalcomApplicationHelper.PRE_ICS) MalcomMainLifecycleDispatcher.get().onActivityResumed(this);
        }
    
        @Override
        protected void onPause() {
            super.onPause();
            if (MalcomApplicationHelper.PRE_ICS) MalcomMainLifecycleDispatcher.get().onActivityPaused(this);
        }
    
        @Override
        protected void onStop() {
            super.onStop();
            if (MalcomApplicationHelper.PRE_ICS) MalcomMainLifecycleDispatcher.get().onActivityStopped(this);
        }
    
        @Override
        protected void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            if (MalcomApplicationHelper.PRE_ICS) MalcomMainLifecycleDispatcher.get().onActivitySaveInstanceState(this, outState);
        }
    
        @Override
        protected void onDestroy() {
            super.onDestroy();
            if (MalcomApplicationHelper.PRE_ICS) MalcomMainLifecycleDispatcher.get().onActivityDestroyed(this);
        }
    }
Clone this wiki locally