Saving data from various Ragments

Asked

Viewed 56 times

0

I have a slide ( using the material-intro lib) that has several fragments, I need to save the data that are typed in those edittext fragments when I close this slide, I’m trying via Input but I’m not getting.

How I’m saving on Internet on Facebook:

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    txtnome = view.findViewById(R.id.txt_nome);
    final Usuario user = new Usuario();

    txtnome.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            Intent intent = new Intent();
            intent.putExtra("nome",txtnome.getText().toString());
            validado = !txtnome.getText().toString().isEmpty();
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });
}

How I’m trying to search in the actvity that opens after closing the slides:

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_INTRO) {
        if (resultCode == RESULT_OK) {
            Intent intent = new Intent();

            String nome = intent.getStringExtra("nome");
            String altura = intent.getStringExtra("altura");
            Toast.makeText(this, "Nome: " + nome, Toast.LENGTH_SHORT).show();
            Toast.makeText(this, "Altura: " + altura, Toast.LENGTH_SHORT).show();
            PreferenceManager.getDefaultSharedPreferences(this).edit()
                    .putBoolean(PREF_KEY_FIRST_START, false)
                    .apply();
        } else {

they return null

  • Try using a sharedpreferences for this. Much simpler.

  • @Lmaker is that I wanted to save only when finishing the slides, but if there is no way will sharedpreferences even

No answers

Browser other questions tagged

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