Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

android - 如何在Android应用程序的“活动”之间传递数据?(How do I pass data between Activities in Android application?)

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

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

On clicking sign-out , I will be passing the session id of the signed in user to sign-out.

(点击sign-out ,我将传递已登录用户的session id以便退出。)

Can anyone guide me on how to keep session id available to all activities ?

(谁能指导我如何使session id可供所有activities ?)

Any alternative to this case

(这种情况的任何替代方法)

  ask by UMAR translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your current Activity, create a new Intent :

(在您当前的活动中,创建一个新的Intent :)

String value="Hello world";
Intent i = new Intent(CurrentActivity.this, NewActivity.class);    
i.putExtra("key",value);
startActivity(i);

Then in the new Activity, retrieve those values:

(然后在新的活动中,检索以下值:)

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("key");
    //The key argument here must match that used in the other activity
}

Use this technique to pass variables from one Activity to the other.

(使用此技术将变量从一个活动传递到另一个活动。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...