重複の可能性:
Androidのアクティビティ間でデータを渡す
メインアクティビティから作成した別のアクティビティに文字列を渡そうとしています。どうすればいいですか?
重複の可能性:
Androidのアクティビティ間でデータを渡す
メインアクティビティから作成した別のアクティビティに文字列を渡そうとしています。どうすればいいですか?
情報をエクストラとしてバンドルに保存することをお勧めします。以下のコードをご覧ください
これはあなたの最初の活動になります
String customerName = "Bob";
Bundle b = new Bundle();
Intent myIntent = new Intent(v.getContext(),work.class);
b.putString("Name", customerName);
myIntent.putExtras(b);
v.getContext().startActivity(myIntent);
次に、他の(2番目の)アクティビティの情報にアクセスするには、以下のコードを参照してください
Bundle b = getIntent().getExtras();
String name = b.getString("customerName");
これを試して
FirstActivity
Bundle bundle = new Bundle();
bundle.putString("Your_KEY", "YOUR_STRING_VALUE");
Intent newIntent = new Intent(FirstActivity.this.getApplicationContext(), SecondActivity.class);
newIntent.putExtras(bundle);
startActivityForResult(newIntent, 0);
SecondActivity
Bundle bundle = SecondActivity.this.getIntent().getExtras();
String s = bundle.getString("Your_KEY");
secondActivityで
public static String myName;
myName="ミゲル";
mainActivityで取得したい場合:
String s1;
s1= secondActivity.myName;