0

i have a listview in which i have some list of data i am sending it to other activity on click

i am sending data with intent

Intent i = new Intent(MainActivity.this,AppDiscription.class);
                    i.putExtra("NAME", s);
                    i.putExtra("AMT", Appname);
                    i.putExtra("COUNT", cnvert);
                    i.putExtra("SELECTEDID", selectedFromList);
                    startActivity(i);

on receiving activity:

if (extras != null) {

            Appname = extras.getString("NAME");
            total = extras.getString("AMT");
            count = extras.getString("COUNT");
            selected = extras.getString("SELECTEDID");
}

now i have to save "selected" into a variable on this activity so that i can compare it with new "selected" data which will came with next intent when i will click on listview.

Nikhil
  • 51
  • 2
  • 9

3 Answers3

1

Use an ArrayList and add all the selected strings as they come. And compare this way:

list.get(last) == list.get(last-1);

but if you are interested in comparing only the previous and the newly created value.

use sharedprefrence

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
0

How do you get your "extras" object? It is a bundle from the activity's intent, right?

 final Bundle extras = this.getIntent().getExtras();
Marius M
  • 496
  • 9
  • 16
0

//inside onCreate()

SharedPreferences  preferences = getPreferences(MODE_PRIVATE); 
SharedPreferences.Editor editor = preferences.edit();

//reading last saved selectedID

lastSavedSelected = preferences.getString("selectedID", "defaultID");

//saving new selectedID

editor.putString("selectedID", selected); 
editor.commit();
Vasudev
  • 1,936
  • 19
  • 17