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.
putExtra() method is used for send the data, data in key-value pair key is variable name and value can be Int, String, Float etc. getStringExtra() method is for getting the data(key) which is send by above method. according the data type of value there are other methods like getIntExtra(), getFloatExtra()
In activity1 , in onCreate() , you can get the String message by retrieving a Bundle (which contains all the messages sent by the calling activity) and call getString() on it : Bundle bundle = getIntent(). getExtras(); String message = bundle. getString("message");
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");
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");
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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With