![](/img/trans.png)
[英]How to get Data from an activity from other activity ..in android..?
[英]Send data from 1 activity to other activity via intent in android.. i want send SongName to next activity
Intent in = new Intent(MainActivity.this, Player.class);
String SongName = SpinSongSelector.getSelectedItem().toString ();
startActivity (in);
我想將SongName發送到下一個活動
在您的第一次活動中嘗試一下,
Intent intent = new Intent(MainActivity.this, Player.class);
String SongName = SpinSongSelector.getSelectedItem().toString ();
intent.putExtra("message", SongName);
startActivity(intent);
然后在第二個活動中獲取您的字符串,如下所示
Bundle bundle = getIntent().getExtras();
String message = bundle.getString("message");
然后將此字符串設置為text-view(這不是必需的,僅供參考,如果要檢查是否具有正確的字符串)
TextView txtView = (TextView) findViewById(R.id.your_resource_textview);
txtView.setText(message);
在startActivty之前使用此行:
intent.putExtra("SongName",SongName);
然后從目標活動中檢索它。
只是使用
發送的第一個活動:
Intent in = new Intent(MainActivity.this, Player.class);
String SongName = SpinSongSelector.getSelectedItem().toString ();
in.putExtra("data",SongName);
startActivity (in);
參加另一項活動:
String Sname = getIntent().getExtras().getString("data");
要查看意圖的詳細信息,請參見此處: http : //developer.android.com/guide/components/intents-filters.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.