This may be a stupid question, but I cannot find much specific information on the Internet.
Suppose I have 2 actions: MainActivity and Secondactivity. The main activity has a button to go to the second action. The second action has a button that goes back to the main activity (very simple code below).
I am trying to understand Android memory management and why I am doing this test.
My question is:
When I constantly go back and forth between actions, looking at the memory graph in the Android studio, I see a blue graph that never returns to the allocated memory that it had when the application started. Do I have a memory leak? (Perhaps this is not the case as the main code). But why does it never return to the original allocated memory at the beginning?
The main activity has only this method:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btnTest = (Button) findViewById(R.id.btnTest); btnTest.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(null, "test"); finish(); startActivity(new Intent(MainActivity.this, SecondActivity.class)); } }); }
While SecondAcitivity just goes back to the first and creates a few buttons
public class SecondActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); Button btnTest = (Button) findViewById(R.id.btnTest); btnTest.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(null, "test"); finish(); startActivity(new Intent(SecondActivity.this, MainActivity.class)); } }); }
}

source share