Possible Duplicate:
Passing data between activities in Android
Ok Lets say that in my Activity1.java there is a variable called date
If I declare it as static, in my Activity2 I can recall its value just by writing Activity1.date.
If it’s not static I can when starting activity2 pass the value of date via Bundle.
Both ways are working.
My question is which is most preffered and has less disadvantages?
Static is bad for many reasons, primarily because it is umm… static. It means that it will be always taking memory and also you will have only one instance of your field to share across all instances of your activity.
Because of this it can you bite your in so many places in so many subtle ways. For instance – if you write several unit tests for the same activity, the value will be shared, therefore your tests will not be independent. Or another use case: you have several instances of your activity on the stack – they all will share the value, which in many cases is not what you want.
The bottom line: do not do static. Static can save you a line or two of code but can introduce a lot of trouble. By the way it is not specific to android, it is true for any platform