Deepa MG Deepa MG - 10 months ago 69
Android Question

what is difference between onCreateView() and getView(),Can I use these in Activity()?

I am confused about usage of


1. Can i use all these three in my

2. Should i compulsorily have different
for each?

Answer Source

Here is description o these methods from Google Developer website:


It gets called when the activity is starting.

This is where most initialization should go:

  • calling setContentView(int) to inflate the activity's UI,
  • using findViewById(int) to programmatically interact with widgets in the UI,
  • calling managedQuery(, String[], String, String[], String) to retrieve cursors for data being displayed, etc.


It is not a lifecycle method for activity. It's just a member method which will be used for specified tasks as said in doc.

Standard implementation of android.view.LayoutInflater.Factory.onCreateView used when inflating with the LayoutInflater returned by getSystemService. This implementation does nothing and is for pre-android.os.Build.VERSION_CODES.HONEYCOMB apps. Newer apps should use onCreateView(View, String, Context, AttributeSet). To rely of call of onCreateView() in Activity is bad programming.

If you are using this method for Fragments then,

It will be Called to have the fragment instantiate its user interface view.


This method is available for Fragments only.

It gets the root view for the fragment's layout (the one returned by onCreateView(LayoutInflater, ViewGroup, Bundle)), if provided.