Reputation: 563
This is my string:
private final String easyPuzzle ="630208010200050089109060030"+
"008006050000187000060500900"+
"09007010681002000502003097";
I want to show this string on the another activity at the 9*9 sudoku board.
Upvotes: 55
Views: 122278
Reputation: 51
First Activity Code :
Intent mIntent = new Intent(ActivityA.this, ActivityB.class);
mIntent.putExtra("easyPuzzle", easyPuzzle);
Second Activity Code :
String easyPuzzle = getIntent().getStringExtra("easyPuzzle");
Upvotes: 2
Reputation: 746
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);
Now go to 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("key");
}
now "yourPreviousPzl" is your desired string.
Upvotes: 6
Reputation: 1129
In ActivityOne,
Intent intent = new Intent(ActivityOne.this, ActivityTwo.class);
intent.putExtra("data", somedata);
startActivity(intent);
In ActivityTwo,
Intent intent = getIntent();
String data = intent.getStringExtra("data");
Upvotes: 7
Reputation: 471
In activity1
String easyPuzzle = "630208010200050089109060030"+
"008006050000187000060500900"+
"09007010681002000502003097";
Intent i = new Intent (this, activity2.class);
i.putExtra("puzzle", easyPuzzle);
startActivity(i);
In activity2
Intent i = getIntent();
String easyPuzzle = i.getStringExtra("puzzle");
Upvotes: 18
Reputation: 497
Post Value from
Intent ii = new Intent(this, GameStartPage.class);
// ii.putExtra("pkgName", B2MAppsPKGName);
ii.putExtra("pkgName", YourValue);
ii.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(ii);
Get Value from
pkgn = getIntent().getExtras().getString("pkgName");
Upvotes: 3
Reputation: 1879
Most likely as others have said you want to attach it to your Intent
with putExtra
. But I want to throw out there that depending on what your use case is, it may be better to have one activity that switches between two fragments. The data is stored in the activity and never has to be passed.
Upvotes: 1
Reputation: 5542
You need to pass it as an extra:
String easyPuzzle = "630208010200050089109060030"+
"008006050000187000060500900"+
"09007010681002000502003097";
Intent i = new Intent(this, ToClass.class);
i.putExtra("epuzzle", easyPuzzle);
startActivity(i);
Then extract it from your new activity like this:
Intent intent = getIntent();
String easyPuzzle = intent.getExtras().getString("epuzzle");
Upvotes: 151