2011-07-15 85 views

回答

115

你需要把它作爲一個額外的:從您的新活動

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"); 
+0

做你把它放在'setContentView(R.layout.activity);'後面? – Bachask8

+0

@ Bachask8你可以做到!通常你把'intent intent = getIntent(); String easyPuzzle = intent.getExtras()。getString(「epuzzle」);'in onCreate – ymerdrengene

5
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字符串。

1

最有可能像其他人所說你想附加到您的IntentputExtra。但是我想拋棄那些依賴於你的用例的東西,最好有一個在兩個片段之間切換的活動。數據存儲在活動中,永遠不必傳遞。

3

崗位價值從

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"); 
14

在活動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"); 
相關問題