7*4 2010-01-19 06:06 采纳率: 50%
浏览 521
已采纳

在 Android 应用程序中,我如何在活动之间传递数据?

I have a scenario where, after logging in through a login page, there will be a sign-out button on each activity.

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

转载于:https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application

  • 写回答

30条回答 默认 最新

  • hurriedly% 2010-01-19 06:12
    关注

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(29条)

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决