如何通过意图将标签活动中的值发送到活动

时间:2013-04-26 09:27:20

标签: android android-intent

我想从此活动发送价值

public class HomeActivity extends android.app.TabActivity
{
    String uid;
protected void onCreate(Bundle savedInstanceState) 
      {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_home);
     TabHost tabHost = getTabHost();
     Intent intent = getIntent();
     uid = intent.getStringExtra("uid");  
     // Tab for ActivityOne
     TabSpec photospec = tabHost.newTabSpec("Home");
     photospec.setIndicator("Home", getResources().getDrawable(R.drawable.one));
     Intent photosIntent = new Intent(this, TabhomeActivity.class);
     photosIntent.putExtra("uid", uid);
     // startActivityForResult(photosIntent,0);
     photospec.setContent(photosIntent);

     // Tab for ActivitySecond
     TabSpec songspec = tabHost.newTabSpec("Today's Meeting");
     // setting Title and Icon for the Tab
     songspec.setIndicator("Today's Meeting",
                                          getResources().getDrawable(R.drawable.one));
     Intent songsIntent = new Intent(this,TodaysmeetingActivity.class);
     songspec.setContent(songsIntent);
     // Adding all TabSpec to TabHost
     tabHost.addTab(photospec); // Adding photos tab
     tabHost.addTab(songspec); // Adding songs tab  
    }
 }

参加此活动..

public class TabhomeActivity extends Activity {

Button button1;
Button button2;
Button button3;
TextView txtview,shwname;
String uid;

@Override
public void onCreate(Bundle savedInstanceState) 
{ 

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tabhome);
    Intent intent = getParent().getIntent();
    uid = intent.getStringExtra("uid");
    shwname=(TextView)findViewById(R.id.textView3);
    shwname.setText("Hi\t"+uid);
 }
谁能帮助我?请。提前谢谢。

2 个答案:

答案 0 :(得分:0)

请尝试以下操作。

Intent intent = getIntent();
Bundle extras = intent.getExtras();
uid = getIntent().getExtras().getString(YOUR_KEY);  

类似地,将数据设置为意图使用时

extras.putString(YOUR_KEY, YOUR_VALUE);

答案 1 :(得分:0)

发送时:

Intent i = new Intent();
intent.putString("uid", uid);

收到时:

Intent intent = getIntent();
Bundle extras = intent.getExtras();
uid = getIntent().getExtras().getString("uid");  

或(使用捆绑):

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    savedInstanceState = getIntent().getExtras();
    uid = savedInstanceState.getString("uid");
}