Android Studio, how to collect data from other screens and show on the last screen?

Asked

Viewed 476 times

1

I have an app with 5 screens,

  • The first screen the basic user information where user inserts the information;

  • In the second screen the information about your interests;

  • On the third screen your goals;

And so next, I wanted that when he presses himself on screen 4 the next screen button appears all the information that he informed.

  • You have two choices to make. One would be to use Bundle to pass the information between the Activitys and another would be to use SharedPreferences!

  • Where Javascript Enters?

  • Oops sorry I didn’t see the tag Javascript, but it might be a tip for him, because I think it might be an alternative!

1 answer

1


There is a library that facilitates the transport of objects between classes.

Is the Parceler!

Follow an example:

Add the following dependencies to your build gradles.:

dependencies {
    …
    compile 'org.parceler:parceler:1.0.4'
    compile 'org.parceler:parceler-api:1.0.4’
}

Example class with values we will carry from a Activity the other:

Values.class

import org.parceler.Parcel;
@Parcel
public class Valores {
    String nome;
    String sobrenome;
    Integer idade;
    Boolean masculino;
    String rua;
    String bairro;
}

Sending :

final Intent intent = new Intent(this, Step1.class);
Valores valores = new Valores();
valores.nome = "Thiago";
valores.sobrenome = "Domacoski";
valores.idade = 32;
intent.putExtra("valores", Parcels.wrap(valores));
startActivity(intent);

Receiving :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_step1);

    if(null != getIntent().getParcelableExtra("valores")){

        Valores valores = Parcels.unwrap(getIntent().getParcelableExtra("valores"));

    }
}
  • I’ll try it here, thanks anyway :)

  • Thanks a lot for the help, I am very beginner, where I put Values.class, is inside the mainpage file.java?

  • It’s from the screen where you’re sending...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.