-2

I want to make an app which plays sounds with different amount of times between sounds but I don't know how to do it. The amount of times are defined by the user in EditText in a setting activity and then the songs are played in another activity so I need to link the EditText value in the other activity. Here is my code to transform the content of my EditText into a variable but I don't know how to use it in my other interface :

    EditText myEdit = (EditText) findViewById(R.id.editText1);
    String myEditValue = myEdit.getText().toString();
    time = Integer.parseInt(myEditValue);

It would be even better if someone can tell me how to transfer my EditText value in an enum but if you only know how to transfer between activities and not from an activity to an enum it will be ok.

Here is my enum code :

public enum phaseTimer {
WAITING("APPUYEZ", valueInEditText1),
LOADING("ATTENTE", valueInEditText2),
ON_YOUR_MARK("A VOS MARQUES", valueInEditText3),
READY("PRET", valueInEditText4),
GO("PARTEZ", valueInEditText5);

public String message;
public int time;
phaseTimer(String message, int time) {
    this.message = message;
    this.temps = temps;
}
public String getMessage() {
    return message;
}

}

Rémy Menard
  • 64
  • 1
  • 8
  • Possible duplicate of [How do I pass data between Activities in Android application?](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – Martin De Simone Sep 10 '17 at 21:01

2 Answers2

0

Intent i = new Intent(this, theotheractivityname.class); i.putExtra("myEditValue",myEditValue ); startActivity(i);

from the other activity, you can get your string with

String newString;
Bundle extras = getIntent().getExtras();
    newString= extras.getString("myEditValue");
Charor
  • 94
  • 1
  • 12
0

This is a simple way here:

Intent intent = new Intent(getBaseContext(), YourClass.class);
intent.putExtra("EXTRA_SESSION_ID", yourVariable);
startActivity(intent);

Access that intent on next activity

String s = getIntent().getStringExtra("EXTRA_SESSION_ID");

Credit to this answer: How do I pass data.....

king_abu1918
  • 284
  • 2
  • 6