开发者

Is it possible to free up memory by finishing an activity after calling another?

Hopefully the titl开发者_高级运维e 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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜