Search code examples
androidglobal-variablesconventions

Global variables in Android


Is possible to define, in Android, variables that are shared between more Activities? I tried to use "special purpose" classes, but i was looking for the best-pratice.

I already looked for similar questions, but i didn't find an exact answer to this question.


Solution

  • If you're looking to send a variable from 1 activity to the next, put it in the Intent. If you really have data that needs to be shared between all activities (such as login information or key data structures used by most/all activities) then you should use a singleton pattern.