-4

I am fresher in Android field kindly explain these lines especially setContentView(R.layout.activity_display_message);

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_message);
    }
elahiammar
  • 129
  • 13
  • 4
    you need to google properly. and refer [documentation](http://developer.android.com/reference/android/app/Activity.html#setContentView%28android.view.View%29) – MysticMagicϡ Nov 10 '14 at 10:43
  • 2
    When you start your app the screen which gets loaded is called Activity which gets loaded by calling its onCreate() method and then it sets the UI by calling setcontentview(the xml file for the UI) – therealprashant Nov 10 '14 at 10:46
  • thanks but what is the purpose of Bundle? – elahiammar Nov 10 '14 at 10:46
  • 1
    @MuhammadAmmarElahi bundle are the extra bits, in this case this is empty if its the first time ur app runs on the device, – nafas Nov 10 '14 at 10:48
  • 1
    [savedInstanceState - If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.](http://developer.android.com/reference/android/app/Activity.html#onCreate%28android.os.Bundle%29) – MysticMagicϡ Nov 10 '14 at 10:48
  • It is a good tradition to grab a book on and exercise the "Hello World" example before claiming to be a developer... – Gyro Gearless Nov 10 '14 at 11:10

1 Answers1

3

As the javadoc says, you are inflating a layout resource by its id:

public void setContentView (int layoutResID)

Added in API level 1 Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.

Parameters : layoutResID -> Resource ID to be inflated.

http://developer.android.com/reference/android/app/Activity.html#setContentView(int)


The Bundle object have information to restore your activity to a previous state.

The saved data that the system uses to restore the previous state is called the "instance state" and is a collection of key-value pairs stored in a Bundle object.

http://developer.android.com/training/basics/activity-lifecycle/recreating.html

Eduardo Briguenti Vieira
  • 4,351
  • 3
  • 37
  • 49
  • 2
    To Inflate is to instantiate a layout XML file into its corresponding View objects. See here: http://stackoverflow.com/questions/4576330/what-does-it-mean-to-inflate-a-view-from-an-xml-file – Eduardo Briguenti Vieira Nov 10 '14 at 11:06