I have a super class which is in a library. This library take care of initializing some basic layout components and other stuff. My problem is that it takes 1.x seconds to load the layout, and shows the default layout for a while, before setting the child-specified layout.
This is the method of my super class:
public void InitializeWindow(Activity act, int layoutResourceId, String windowTitle,
Object menuAdapter, int slideMenuMode) {
super.setContentView(layoutResourceId);
super.setBehindContentView(R.layout.menu_frame);
this.menuAdapter = menuAdapter;
this.slideMenuMode = slideMenuMode;
setWindowTitle(windowTitle);
initializeSlidingMenu();
}
This is called this way:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.InitializeWindow(this, R.layout.activity_home, "\t\tHome",
new MenuAdapter(this, R.menu.slide_menu), SlidingMenu.TOUCHMODE_FULLSCREEN);
}
The application works like a charm, but it takes, as I said around 1.x seconds to load the layout passed from the child-class. Why does this happen?
By request, this is my initializeSlideMenu()
method:
public void initializeSlidingMenu() {
this.setSlidingActionBarEnabled(true);
getSlidingMenu().setBehindOffsetRes(R.dimen.actionbar_home_width);
getSlidingMenu().setShadowWidthRes(R.dimen.shadow_width);
getSlidingMenu().setShadowDrawable(R.drawable.shadow);
getSlidingMenu().setTouchModeAbove(slideMenuMode);
getSlidingMenu().setBehindScrollScale(0.25f);
ListView v = new ListView(this);
v.setBackgroundColor(Color.parseColor("#000000"));
v.setAdapter((ListAdapter) menuAdapter);
getSlidingMenu().setMenu(v);
}
InitializeWindow
a constructor. Why does your superclass not do all the stuff inonCreate()
? -- What's going on ininitializeSlidingMenu()
? – PrestidigitationinitializeSlidingMenu()
I initalize the slidingmenu, please see my edit in a few seconds. – ArchegoniumInitializeWindow()
takes to-much time to create a layout while your base class already completed the drawing view for current activity. And prepared the windows for Activity. – HoroscopeTextView
. That's whats bothering me. – Archegonium@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(layoutResourceId);}
In this you have to callsetContentView()
from Child Activity not from Base Activity'sInitializeWindow()
. – Horoscopesuper.setContentView(layoutResourceId);
fromInitializeWindow()
. Just for try purpose and let me know. Because same things works in my case. – HoroscopesavedInstanceState
; we just don't know. I would recommend you do some profiling or at least log system time after calls to third party code to narrow the search. – PrestidigitationInitializeWindow()
Will be called in that time your Base Activity completes the configure and prepared windows. So you have to callsetContentView()
from Child Activity and if possible don't do much work on base class's methods so your child Activity get enough time to prepare layout after that you can call the other stuff which prepared other view options. – HoroscopeonCreate()
has returned. I can see no reason whysetContentView()
needs to be called from the final child class, either. – Prestidigitation