Does Android transmit persistent information in bundles or uses a singleton pattern?

It’s just interesting that it’s better to use it to transfer information between actions, add it to a package or use a singleton class to store and access this data. I used both in the past for various third-party projects, but now I am working on an Android project that is much larger in scale, so I would prefer to do everything right at the beginning.

My application authenticates users and then will perform various requests based on this id. To minimize the connection between actions, I would think that simply adding an identifier to the package and then providing each activity request with the information that it needs would be a better choice; however, to increase responsiveness, I tended to use a singleton class to store persistent information, preventing more requests than needed.

+5
source share
5 answers

Application . Application Android , . , Singleton, Application Android .

. , getter/setter ( ) / . ( ) Bundle, . Bundle, , , - () , .

+7

, bunlde, - , - (, , ..). , , .

+1

- SharedPreferences, userId, . , Application, , .

+1

- . , , , .

0

The singleton pattern has poor results. For example: from the main activity you cause secondary activity. A phone call interrupted your work. After the end of the phone call, Android is trying to bring additional activity to the screen. Here's my nightmare - many users complain about exceptions - Google gave me NULL pointers in my singleton. Therefore, you need to provide not only singleton, but all data inside singleton should be like singleton. This is a very complicated matter :(

0
source

All Articles