0
People would like to know how to pass the contents of a plaintext that is in Mainactivity directly to Main3activity, without having to import to Main2activity for later to Main3activity.
User passes through Main2activity before going to Main3acitvity.
In the Mainactivity has a plaintext (etPlanetaVive) where the user informs which planet he lives on.
Mainactivity.java
ackage genesysgeneration.third;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private EditText etPlantaVive;
private Button btnNext_01;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etPlantaVive=(EditText)findViewById(R.id.etPlanetaVive);
btnNext_01=(Button)findViewById(R.id.btnNext_01);
btnNext_01.setOnClickListener(this);
}
public void onClick(View v){
Intent it = new Intent(this, Main2Activity.class);
it.putExtra("planetaVive", etPlantaVive.getText().toString());
startActivity(it);
}
}
I export the plaintext contents to Main2activity using the code it.putExtra("planetaVive", etPlantaVive.getText().toString());
In the Main2activity has a plaintext where the user informs which planet he would like to live on.
Main2activity.java.
package genesysgeneration.third;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Main2Activity extends AppCompatActivity implements View.OnClickListener{
private String planetaVive;
private EditText etPlanetaDesejo;
private Button btnNext_02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
planetaVive = getIntent().getStringExtra("planetaVive");
etPlanetaDesejo=(EditText)findViewById(R.id.etPlanetaDesejo);
btnNext_02=(Button)findViewById(R.id.btnNext_02);
btnNext_02.setOnClickListener(this);
}
public void onClick(View v){
Intent it = new Intent(this, Main3Activity.class);
it.putExtra("planetaVive", planetaVive);
it.putExtra("planetaDesejo", etPlanetaDesejo.getText().toString());
startActivity(it);
}
}
I wish I didn’t have to import the contents of the first plaintext (etPlanetaVive) => planetaVive = getIntent().getStringExtra("planetaVive");
I would like to do this only in the third (Main3activity).
In Main3activity appears this:
Main3activity.java.
package genesysgeneration.third;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Main3Activity extends AppCompatActivity {
private String planetaVive, planetaDesejo;
private TextView tvFinalPlanetaVive, tvFinalPlanetaDesejo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
planetaVive = getIntent().getStringExtra("planetaVive");
planetaDesejo = getIntent().getStringExtra("planetaDesejo");
tvFinalPlanetaVive=(TextView)findViewById(R.id.tvFinalPlanetaVive);
tvFinalPlanetaVive.setText(tvFinalPlanetaVive.getText().toString() + planetaVive);
tvFinalPlanetaDesejo=(TextView)findViewById(R.id.tvFinalPlanetaDesejo);
tvFinalPlanetaDesejo.setText(tvFinalPlanetaDesejo.getText().toString() + planetaDesejo);
}
}
As you saw, I had to move the contents of the first Activity to the second, only then to the third.