发出 oAuth 请求时 onSaveInstanceState 问题

发布于 2024-10-07 16:32:00 字数 523 浏览 0 评论 0原文

这是我的场景:

1)在我的活动中,用户按下“授权”按钮。

2) 应用程序打开 WebView,其中加载 Twitter 页面,并要求用户输入登录名和密码,然后按“允许”按钮。 (oAuth 实现,Twitter 需要它才能将您的应用程序与 Twitter 集成)

3)远程服务器将带有令牌和秘密的 Intent 传递回我的 Activity,然后我的 Activity 重新获得控制权。

我的问题:

启动此活动时,通过Intent传递RowID变量。当活动暂停或屏幕方向更改时,我将该值保存在 onSavedInstanceState 中。在步骤 3 中,当我的活动重新获得控制权时,我会释放此 RowID 变量。我明白为什么,基本上 Activity 正在执行 onResume 并从 Twitter 接收意图,其中没有提及 RowID。 那么,如何保存 RowID 值并在活动恢复时检索它?我可以将其保存到“首选项”中,但这样做正确吗?

任何建议, 谢谢。

Here is my scenario:

1) in my activity, user pushes Authorize button.

2) app opens WebView, in which Twitter page is loaded and user is asked to enter login and password and press Allow button. (oAuth implementation, Twitter requires it in order to integrate your app with Twitter)

3) Remote server passes Intent with Token and Secret back to my Activity, and my Activity then gets control back.

My Problem:

When starting this activity, through Intent, RowID variable is passed. This value I save in onSavedInstanceState when activity is pausing or when screen orientation is changed. In step 3, when my activity receives control back I loose this RowID variable. I can see why, basically activity is doing onResume and receiving intent from Twitter where there is no mention of RowID. So, how can I save my RowID value and retrieve it when activity is resumed? I could save it to Preferences, but is that right thing to do?

Any suggestions,
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡紫姑娘! 2024-10-14 16:32:00

对于这种情况,首选项是保存状态的正确方法。简单、容易、快捷。

Preferences is the correct way to save state for such cases. simple, easy quick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文