tags:

views:

79

answers:

2

Hopefully the title wasn't to confusing but what I meant was the following:

Lets say activity A starts activity B by calling:

Intent myIntent = new Intent(Activity_A.this, Activity_B.class);
Activity_A.this.startActivity(myIntent);

Could I save/free up some memory by finishing Activity_A after Activity_B is begun (if thats even possible). Maybe through the following:

Intent myIntent = new Intent(Activity_A.this, Activity_B.class);
Activity_A.this.startActivity(myIntent);
Activity_A.finish();

Or would Acitivty_A call startActivity() and wait for Activity_B to finish before it called finish()?

The idea would then be that when the users end with Activity_B, it would just restart Acitivity_A (and finish itself in a similar fashion)? Would this create too much overhead? Thanks for any answers and I apologize if the formatting of this post isn't correct.

A: 

This will not necessarily save any memory, and I'm not immediately sure of any way to do this. When you go from one activity to another, the first activity is closed and its state bundled. It's not really open anymore at that point.

Michael Pardo
The first activity's state is bundled but is this bundle must be saved somewhere no? Is the amount of memory that is used up by this saved state anything significant? I don't think I understand very well how the system deals with these saved states.
Fizz
Look at your onCreate method, it takes in a bundle.Take a look at this Android architecture video too. http://developer.android.com/videos/index.html#v=QBGfUs9mQYY
Michael Pardo
A: 

What you are trying to do is platform's job. You shouldn't really care about optimizations like this.
Still, if you do, this will work just fine:

Intent intent = new Intent(this, OtherActivity.class);
startActivity(intent);
finish(); // finishes this
alex