這是我的字符串:從一個活動傳遞一個字符串到另一個活動中的Android
private final String easyPuzzle ="630208010200050089109060030"+
"008006050000187000060500900"+
"09007010681002000502003097";
我想顯示在在9×9的數獨板的另一個活動這個字符串。
這是我的字符串:從一個活動傳遞一個字符串到另一個活動中的Android
private final String easyPuzzle ="630208010200050089109060030"+
"008006050000187000060500900"+
"09007010681002000502003097";
我想顯示在在9×9的數獨板的另一個活動這個字符串。
你需要把它作爲一個額外的:從您的新活動
String easyPuzzle = "630208010200050089109060030"+
"008006050000187000060500900"+
"09007010681002000502003097";
Intent i = new Intent(this, ToClass.class);
i.putExtra("epuzzle", easyPuzzle);
startActivity(i);
然後提取它是這樣的:
Intent intent = getIntent();
String easyPuzzle = intent.getExtras().getString("epuzzle");
private final String easyPuzzle ="630208010200050089109060030"+
"008006050000187000060500900"+
"09007010681002000502003097";
Bundle ePzl= new Bundle();
ePzl.putString("key", easyPuzzle);
Intent i = new Intent(MainActivity.this,AnotherActivity.class);
i.putExtras(ePzl);
startActivity(i);
現在去AnotherActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_another_activity);
Bundle p = getIntent().getExtras();
String yourPreviousPzl =p.getString("abc");
}
現在「yourPreviousPzl」是你的願望d字符串。
最有可能像其他人所說你想附加到您的Intent
與putExtra
。但是我想拋棄那些依賴於你的用例的東西,最好有一個在兩個片段之間切換的活動。數據存儲在活動中,永遠不必傳遞。
崗位價值從
Intent ii = new Intent(this, GameStartPage.class);
// ii.putExtra("pkgName", B2MAppsPKGName);
ii.putExtra("pkgName", YourValue);
ii.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(ii);
獲得價值從
pkgn = getIntent().getExtras().getString("pkgName");
在活動1
String easyPuzzle = "630208010200050089109060030"+
"008006050000187000060500900"+
"09007010681002000502003097";
Intent i = new Intent (this, activity2.class);
i.putExtra("puzzle", easyPuzzle);
startActivity(i);
在活性2
Intent i = getIntent();
String easyPuzzle = i.getStringExtra("puzzle");
做你把它放在'setContentView(R.layout.activity);'後面? – Bachask8
@ Bachask8你可以做到!通常你把'intent intent = getIntent(); String easyPuzzle = intent.getExtras()。getString(「epuzzle」);'in onCreate – ymerdrengene