Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
問題があります。メイン クラスの文字列の値をセカンダリ クラスにリコールする必要があります。どうすればメイン クラスの文字列に 2 番目からアクセスできますか? 最初のクラス (LoginActivity) と 2 番目のクラス (DashboardActivity) を取得しました。ダッシュボードで LoginActivity (文字列のユーザー名) の戻り値を取得する必要があります。これを行うにはどうすればよいですか?
DashboardActivityを起動するときに、文字列値をIntent.EXTRAとして渡します。
起動時:
Intent i = new Intent(getBaseContext(), DashboardActivity.class); i.putExtra("MyString", username);
そして、値を取得するには:
Bundle bundle = getIntent().getExtras(); String value = bundle.getString("MyString");