How to compare data from different activities?

1

I'm developing a simple application just to increase my knowledge, and I want to know how I can do to compare data between activities ?

Example :

  

Activity1: In this activity I have variable A that has value 1

     

Activity2: In this other, I have the variable B that has value 2

     

Activity3: And in this a variable C with the value 3

Now what I want to know in activity 0 when I enter the name of the variable A for example, it shows me the value of it and at the same time tell me the lowest value between the other variables of the other activities !

    
asked by anonymous 12.09.2017 / 09:09

1 answer

4

In this case you have 4 options in my view:

1 - You will have to traffic the information from one view to another through intents and in that you read the value with% in the other activity , as in the example below:

Intent intent = new Intent(this, Activity2.class)
intent.putExtra("var1", 10);
startActivity(intent);

//Aqui você vai ler na Activity2
getIntent().getIntExtra("var1", 0) //0 é default se não achar um extra com a key var1

2 - Or save a static class that will store the values for you to compare;

3 - Or save these values in any form of data persistence, either in SharedPreferences or Database;

4 - Or the way I find it simple for the example, having a general activity and the other three being fragments .     

12.09.2017 / 13:27