Hello! The new keyword creates a new instance in the heap each time, right? Hence, the question arose: are resources being expended under such a scheme for invoking a new Activity as in the example on the site ?
public void sendMessage(View view) { Intent intent = new Intent(this, DisplayMessageActivity.class); startActivity(intent); } those. do we create a new instance instance every time? And what will happen to the previously created by the previous click? Will the garbage collector take it? Or maybe it will not be re-created, but the previously created one will be used?
Wouldn't it be more appropriate to do this:
public class MainActivity extends AppCompatActivity { private Intent intent; ... @Override protected void onCreate(Bundle savedInstanceState) { ... intent = new Intent(this, SettingsActivity.class); ... } ... public void btnClick(View view) { startActivity(intent); } ... } those. create an object once in the onCreate event, and then call it when the button is pressed (for example)
Please help me figure out, or send me to learn the basics of creating instances of classes :)