I have many activities in which I need to execute some code on create, this code has to do with display preferences such as different themes, hiding the status bar etc.
This is an example of one of the activites:
public class MainActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
}
}
Base activity in turn has this code:
public class BaseActivity extends Activity{
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// System.out.println("BaseActivity");
}
I’m trying to run some code on create but I cannot manage to do it. How can I run the code from above as soon as possible using BaseActivity?
call super.onCreate(Bundle bundle) in the childs onCreate method to call the onCreate of the parent.
This is a common practice to abstract code from an Activity for reuse in other activities.
e.g.:
I personnaly do this a lot but I often prefer the following for having better maintainable code: