I didn't quite understand how starting a new activity works and how to release memory when doing that.
This is what i have :
Button b1, b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setContentView(R.layout.activity_main);
setReferences();
}
private void setReferences() {
b1= (Button) findViewById(R.id.b1);
b2= (Button) findViewById(R.id.b2);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent newActivity;
switch (v.getId()) {
case R.id.b1:
newActivity = new Intent("com.sblasblasbla.PLAYACTIVITY");
startActivity(newActivity);
break;
case R.id.b2:
newActivity = new Intent("com.sdasdsadsa.THIRDACTIVITY");
startActivity(newActivity);
break;
}
}
}
But when i go to another activity i want to release memory, and if i press the back button(return) from phone to save my activity layout (with background and buttons etc) i mean not to delete them
How can i do that efficiently ? I've heard something with onStop and onDestroy, but i don't know how they work. Also if i destroy activity, it calls again onCreate?