son*_*nix 7 user-interface android
我想知道在活动之间传递对象的最佳做法是什么?我注销的用户在内容项上,应该能够在登录过程后返回此项.因此,我需要在这些活动之间传递内容ID
我看到2个基本选项:
还有其他选择和最佳做法吗?
我建议使用SharedPreferences,它类似于选项 2。它允许您在应用程序关闭后获取 content-id(或字符串或 json 对象)。您还可以在将 content-id 放入共享首选项之前对其进行加密
除了意图(ram)和本地存储(rom/sdcard,包括数据库)之外,我看不到任何其他选项(本地)。
情况 1:您需要在应用程序关闭后恢复活动,
您应该使用本地存储情况2:应用关闭后无需恢复Activity
Run Code Online (Sandbox Code Playgroud)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)
归档时间: |
|
查看次数: |
532 次 |
最近记录: |