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

如何在 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

  • 写回答

11条回答 默认 最新

  • derek5. 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").

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!