In many tutorials on developing mobile applications in java in android studio, I see that almost everyone writes findViewById in the onCreate method, and I write immediately when defining the field (Example in the code below), and I don`t understand why everyone writes component search by ID in the onCreate method, although there seemed to be no differences, Or are they there?
As i do:
private Button asIDo = findViewById(R.id.btn_main);
As others do:
private Button other;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
other = findViewById(R.id.btn_main);
}
Is there a difference in this and what is it? I'm just a beginner and I don't know what the difference is, although it works the same way. Thanks for the answer and sorry for such a dumb question :)