How do I pass data between Activities in Android application?(如何在 Android 应用程序的活动之间传递数据?)
问题描述
我有一个场景,通过登录页面登录后,每个activity
上都会有一个退出按钮
.
I have a scenario where, after logging in through a login page, there will be a sign-out button
on each activity
.
点击 sign-out
时,我将传递已登录用户的 session id
以注销.谁能指导我如何使 session id
对所有 activities
可用?
On clicking sign-out
, I will be passing the session id
of the signed in user to sign-out. Can anyone guide me on how to keep session id
available to all activities
?
这种情况的任何替代方案
Any alternative to this case
推荐答案
最简单的方法是将会话 ID 传递给您用于启动的 Intent
中的注销活动活动:
The easiest way to do this would be to pass the session id to the signout activity in the Intent
you're using to start the activity:
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("EXTRA_SESSION_ID", sessionId);
startActivity(intent);
在下一个活动中访问该意图:
Access that intent on next activity:
String sessionId = getIntent().getStringExtra("EXTRA_SESSION_ID");
Intents 的 docs 有更多信息(查看标题为附加"的部分).
The docs for Intents has more information (look at the section titled "Extras").
这篇关于如何在 Android 应用程序的活动之间传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Android 应用程序的活动之间传递数据?


- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01