Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Which is more efficient?

hey people, I have almost finished writing my first android app. It is a note taking app with add, edit view screens etc...

Initially I was handling moving between screens in a single activity by creating new layout objects such as tables etc... and displaying them. However after some more reading I have changed my method of moving between screens by using different activities for different screens. However each activity that is called as an intent retrieves a large number of variables from the main activity via setExtra and passes back a large number of variables as well.

Now I want my app to be as efficient as possible and I personally think that handling it all in one activity is less memory hungry and processor intensive although this has the negative of meaning variables are always present (and consuming memory) unlink in a separate activity where they are killed on finish(). But you guys are more knowledgeable then me so what do you think is the best way to do it?

like image 421
Crazyfool Avatar asked Feb 03 '11 16:02

Crazyfool


2 Answers

If you launch a new activity for the new screens then you will add that activity to the stack. That way a user can press back and get back to the previous activity. Just changing the layout removes this functionality. I doubt very much you'll have performance issues either way.

Best practice would be to start a new activity, best performance might be to use your current approach.

like image 193
DeliveryNinja Avatar answered Sep 27 '22 20:09

DeliveryNinja


All your activities will reside and run from the same process. So there is no reason you need to pass around a pile of variables. You could (for example) stick them in a singleton which represents your context. When one activity hands over to another it fills in the singleton and the next one picks up its data from there.

Of course if you ever intend an external activity to interact with your ones you may have to rethink this approach, but I think you'd be fine to keep your views as separate activities. Even if memory is ever so slightly higher, I think it's better to do things correctly and only worry about optimization if and only when it becomes obvious you need it.

like image 41
locka Avatar answered Sep 27 '22 21:09

locka