0

I have 1 Activity(Upload) and 1 Fragment(Explorer).

Upload sends a string to Explorer, to then retrieve it back from Explorer.

Flow: Upload > Explorer > Upload

When I try to pass the string by using:

Upload > Explorer

loadButton.Click += delegate {
           var FilePicker = new Intent(this, typeof(FilePickerActivity));
            FilePicker.PutExtra("CodigoReal", foldercreate);
            StartActivity(FilePicker);
        };

and retrieve it in my Fragment class with:

Explorer > Upload

 var Uploaded = new Intent(Activity,typeof(Upload));
            Uploaded.PutExtra("Path", path);
            string foldercreate2 = Uploaded.GetStringExtra("CodigoReal") ?? "La informacion no esta disponible.";
            Uploaded.PutExtra("CodigoReal", foldercreate2);
            Toast.MakeText(Activity, foldercreate2, ToastLength.Short).Show();
            StartActivity(Uploaded);

Data doesn't pass. What am I doing wrong?

Alberto López
  • 107
  • 1
  • 10

2 Answers2

0

You can use SharedPreferences, it's easy to use.

SET

SharedPreferences prefs =
     getSharedPreferences("MisPreferencias",Context.MODE_PRIVATE);

SharedPreferences.Editor editor = prefs.edit();
editor.putString("email", "modificado@email.com");
editor.putString("nombre", "Prueba");
editor.commit();

Get

SharedPreferences prefs =
     getSharedPreferences("MisPreferencias",Context.MODE_PRIVATE);

String correo = prefs.getString("email", "por_defecto@email.com");

full example

Felix Gutierrez
  • 179
  • 1
  • 17
0

I am not familiar with Xamarin, but it seems that you are trying to start new Activity on your backward callback (Explorer > Upload). Instead you always can access your activity using fragment context:

(MyActivityClass)getContext();

And use any appropriate methods. But your technic is not absolutely wrong. If you set your activity launchMode to 'singeTop', then new activity won't be created and existing one will be used. In that case you will receive callback with new intent in onNewIntent activity callback.

Hope, it'll help.

The Dreams Wind
  • 8,416
  • 2
  • 19
  • 49