[英]Best practice: passing objects between Android activities
我想知道在活动之间传递对象的最佳做法是什么? 我注销的用户在内容项上,应该能够在登录过程后返回此项。 因此,我需要在这些活动之间传递内容ID
我看到2个基本选项:
还有其他选择和最佳做法吗?
我建议使用SharedPreferences ,它类似于选项2.它允许您在关闭应用程序后获取content-id(或字符串或json对象)。 您还可以在将content-id放入sharedPreferences之前对其进行加密
除了intent(ram)和本地存储(rom / sdcard,包括数据库),我也看不到任何其他选项(本地)。
案例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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.