如何在Android应用程序的“活动"之间传递数据? [英] How do I pass data between Activities in Android application?

查看:140
本文介绍了如何在Android应用程序的“活动"之间传递数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,在通过登录页面登录后,每个activity上都会有一个登出button.

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");

针对Intent的 docs 具有更多信息(请参阅标题为其他"的部分.)

The docs for Intents has more information (look at the section titled "Extras").

这篇关于如何在Android应用程序的“活动"之间传递数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆