This is what I tested -
View view=getLayoutInflater().inflate(R.layout.activity_main,null);
Log.i("System.out ","view = " + view + "id = "+ view.getId());
setContentView(view);
ly = (LinearLayout)findViewById(R.id.linearlayout);
Log.i("System.out ","linear layout = " + ly + "id="+ly.getId());
View view1=getLayoutInflater().inflate(R.layout.activity_main,null);
Log.i("System.out ","view1 = " + view1 + "id = "+ view1.getId());
setContentView(view1);
ly = (LinearLayout)findViewById(R.id.linearlayout);
Log.i("System.out ","linear layout = " + ly + "id="+ly.getId());
In both cases ly object has different address -
05-10 19:00:36.486: I/System.out(27233): view = android.widget.LinearLayout@41e0ef70id = 2131230720
05-10 19:00:36.731: I/System.out(27233): linear layout = android.widget.LinearLayout@41e0ef70id=2131230720
and
05-10 19:00:36.731: I/System.out(27233): view1 = android.widget.LinearLayout@41e2a5d0id = 2131230720
05-10 19:00:36.736: I/System.out(27233): linear layout = android.widget.LinearLayout@41e2a5d0id=2131230720
So, the above Output will Infer following conclusions :-
[1.] inflate() method will always return new root view object representing the xml hierarchy
[2.] On calling setContentView(view), 'view' will be associated with activity.
So, Now based on these relations , lets understand the output of question in this thread.
On calling - setContentView(R.layout.activity_main),
android system will do inflation. This means that it will create view objects for all elements in xml. Then these views are shown on screen. So, at this point view object in memory is LinearLayout@41e28848. As this represents root view(a Linear layout) hence on calling -
LinearLayout ly = (LinearLayout)findViewById(R.id.linearlayout)
ly will also points to same view LinearLayout@41e28848, which was created on calling setContentView(). So, ly=LinearLayout@41e28848.
This proves the first output line.
Moving on to View view=getLayoutInflater().inflate(R.layout.activity_main,null), this will again create a new view with some different address location (LinearLayout@41e29740).This is manual inflation of xml. But this view object is not associated with current activity as we have not called setContentView(view). Here view=LinearLayout@41e29740
next line - LinearLayout ly1 = (LinearLayout)findViewById(R.id.linearlayout), again gets the view which is active for current activity. This is (LinearLayout@41e28848) which is also the root view. This was actually created inside setContentView() method. Hence, ly1=LinearLayout@41e28848.
And, The next two print statements just print the object they represent i.e, view and ly1.
Thanks.