user3436759
user3436759

Reputation: 3

how can i send information from one activity, receive it in a second activity and sent it to the the main activity?

i would like to send information from one page and receive it in a edit page, and after receiving it i want to save it and send it to the main activity (in android). how can i do it? this is the code from the first page:

    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {

            int position1 = position;
            // i am getting the title of the movie that was pressed
            String search_title = list.get(position).getTitle().toString();
            String search_url = list.get(position).getPhoto_url();
            String search_description = list.get(position).getDescription();

            Intent intent = new Intent(Search_A_Movie.this,Edit_A_Movie.class);

            // i am sending the info of the movie to the edit_a_movie page
            intent.putExtra("item_title", search_title);
            intent.putExtra("item_url", search_url);
            intent.putExtra("item_description", search_description);

            startActivity(intent);

        }
    });

Upvotes: 0

Views: 75

Answers (4)

Naveen Kumar Kuppan
Naveen Kumar Kuppan

Reputation: 1442

You just send the data from one activity

sending like this...

Intent intent = new Intent(Search_A_Movie.this,Edit_A_Movie.class);

            // i am sending the info of the movie to the edit_a_movie page
            intent.putExtra("item_title", search_title);
            intent.putExtra("item_url", search_url);
            intent.putExtra("item_description", search_description);

            startActivity(intent);

get the values in the second activity like this.....

Intent intent = getIntent();
        String name1 = intent.getStringExtra(SENTNAME1);
        String name2 = intent.getStringExtra(SENTNAME2);//replace the above sent name what you have given in the first activity....
        String name3 = intent.getStringExtra(SENTNAME3);

Upvotes: 1

user2689294
user2689294

Reputation: 129

in the second activity

  Bundle d = getIntent().getExtras();
    String item_title = d.getString("item_title");
    String item_url = d.getString("item_url");
    String item_description = d.getString("item_description");

Upvotes: 0

Elias Sh.
Elias Sh.

Reputation: 510

try this:

SharedPreferences sharedPreferences = PreferenceManager
        .getDefaultSharedPreferences(getApplicationContext());

SharedPreferences.Editor editor = sharedPreferences.edit(); 

editor.putString("PASSWORD_KEY", mPassword);
editor.commit();

To get the saved string value from another activity

SharedPreferences sharedPreferences = PreferenceManager
        .getDefaultSharedPreferences(getApplicationContext());
String s = sharedPreferences.getString("PASSWORD_KEY", "");  

Upvotes: 0

fida1989
fida1989

Reputation: 3249

Use SharedPreference. Save in A1 and retrieve in A2 and vice-versa.

Initialization

SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
Editor editor = pref.edit();

Storing Data

editor.putBoolean("key_name", true); // Storing boolean - true/false
editor.putString("key_name", "string value"); // Storing string
editor.putInt("key_name", "int value"); // Storing integer
editor.putFloat("key_name", "float value"); // Storing float
editor.putLong("key_name", "long value"); // Storing long

editor.commit(); // commit changes

Retrieving Data

// returns stored preference value
// If value is not present return second param value - In this case null
pref.getString("key_name", null); // getting String
pref.getInt("key_name", null); // getting Integer
pref.getFloat("key_name", null); // getting Float
pref.getLong("key_name", null); // getting Long
pref.getBoolean("key_name", null); // getting boolean

Deleting Data

editor.remove("name"); // will delete key name
editor.remove("email"); // will delete key email
editor.commit(); // commit changes

Clearing Storage

editor.clear();
editor.commit(); // commit changes

Upvotes: 1

Related Questions