I've been researching this logic from the past week but no luck. Can anyone help me on with it? So the problem where I got stuck is I'm using the beacon concept (Moko Beacon) using bindService where it Scans the beacons till the app has been destroyed. So I get the beacon data all the time.
Here's my code:
public class MainActivity extends AppCompatActivity implements 
              MokoScanDeviceCallback {
private MokoService mMokoService;
private HashMap<String, BeaconXInfo> beaconXInfoHashMap;
public ArrayList<BeaconXInfo> beaconXInfos;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
    beaconXInfoHashMap = new HashMap<>();
    beaconXInfos = new ArrayList<>();
}
public void onScanDevice(DeviceInfo device) {
    final BeaconXInfo beaconXInfo = beaconXInfoParseable.parseDeviceInfo(device);
    if (beaconXInfo == null) {
        return;
    }
    beaconXInfoHashMap.put(beaconXInfo.mac, beaconXInfo);
    updateDevices();
}
private void updateDevices() {
Collections.sort(beaconXInfos, new Comparator<BeaconXInfo>() {
        @Override
        public int compare(BeaconXInfo lhs, BeaconXInfo rhs) {
           Log.e("beaconXinfo", String.valueOf(beaconXInfos.toString())); 
            if (lhs.rssi < rhs.rssi){
                for (int i = 0 ; i < beaconXInfos.size();i++){
                    if ((beaconXInfos.get(i).rssi > -40)){
                        NotificationHelper notificationHelper = new NotificationHelper(MainActivity.this);
                        notificationHelper.CreateNotification(beaconXInfos.get(i).mac,"enter");
                    }else if ((beaconXInfos.get(i).rssi < -40)){
                        NotificationHelper notificationHelper = new NotificationHelper(MainActivity.this);
                        notificationHelper.CreateNotification(beaconXInfos.get(i).mac,"exit");
                    }
                }
            }
            return 0;
        }
    });
    }
The problem lies in the updateDevices() method where I get values continuously till I destroy the app. The log values are as below :
E/beaconXinfo: [BeaconXInfo{name='BeaconX', mac='F5:5E:B1:65:94:4B'}]
E/beaconXinfo: [BeaconXInfo{name='BeaconX', mac='F5:5E:B1:65:94:4B'}, BeaconXInfo{name='UFO', mac='55:46:4F:D2:72:5A'}]
E/beaconXinfo: [BeaconXInfo{name='BeaconX', mac='F5:5E:B1:65:94:4B'}, BeaconXInfo{name='UFO', mac='55:46:4F:D2:72:5A'}, BeaconXInfo{name='null', mac='C8:DE:FE:45:50:02'}] //change in the data
As you can see above there is a change in data in the last log I want to send the data to the server only when there is a change in data in the hashmap.
So first I send the data "F5:5E:B1:65:94:4B" because there is only one value. Next, I need to compare this hashmap with the next hashmap where there's a change in the data called "55:46:4F:D2:72:5A". I need to send this data ignoring the "F5:5E:B1:65:94:4B".
Like same, How to send only this "C8:DE:FE:45:50:02" value comparing with the previous hashmap to the server.
So How to compare the first log of hashmap data with the next series of hashmap data where I can take only the latest value and send it to the server.
I've researched a bunch of question before posting this like below:
How to remove Duplicate value from arraylist in Android
How do I remove repeated elements from ArrayList?
Remove duplicate values from HashMap in Java
Maybe I might be confused with the above which I use in my code.
If anything needs to be added into the code please comment below. Any suggestion and answers would be highly appreciated. Thanks in advance.
 
     
    