我想知道最佳实践是在活动之间传递对象的最佳方法是什么?我注销的用户在一个内容项目上,并且应该能够在登录过程后回到该项目。因此,我需要在这些活动之间传递内容ID
我看到2个基本选项:
还有其他选择和最佳做法吗?
我建议使用类似于选项2的SharedPreferences,它允许您在应用关闭后获取content-id(或字符串或json对象)。您还可以在将content-id放入sharedPreferences之前对其进行加密
除了意图(RAM)和本地存储(ROM / SD卡,包括数据库),我看不到任何其他选项(本地)。
情况1:关闭应用程序后,您需要恢复活动,
应该使用本地存储情况2:您无需在应用关闭后恢复活动
option 1: 0. load the first activity 1. start login_activity (startActivityForResult()) (do not call finish() ) 2. after login is done (call finish()) 3. activity is resumed (if login fail -> redirect to other activity ) option 2: 1. create a public class with a data member to save the content-id/activity class (you may assign singleton design pattern)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句