What is the most efficient way of instanciating variables for performance and memory?
this :
Context context = this;
Resources resources = context.getResources();
Drawable drawable = resources.getDrawable(R.drawable.image);
ListView list = (ListView) context.findViewById(R.id.list);
list.setBackgroundDrawable(drawable);
or this :
((ListView) findViewById(R.id.list)).setBackgroundDrawable(getResources().getDrawable(R.drawable.image));
or it doesn’t matter, it is does the same so I should stick with what I like the most?
Doesn’t matter. The same number of objects are created. I’d prefer the first for sake of readability. I’d skip the first line though.