The onActivityResult method is resetting values

31 Views Asked by At

I'm currently evaluating the functionality of an app across various devices, and I've encountered an issue on one of them. Specifically, when I invoke the onActivityResult method, it functions as expected initially. However, on the second invocation, it seems to reset the data that was previously recorded during the last call. While this behavior is consistent on most devices, there's an exception with this particular device, which inexplicably clears the view when handling activity results.

In brief, when I select products and proceed to choose gifts, the selected products are removed.

The only device in which the issue occurred was Realme 6 - UI 2.0 (Android 11)

In essence, the problem arises when I choose data from another activity using an intent; it appears to reset the data that was previously selected. Here's how the data retrieval process is structured:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Popup_Selected_Result_Product) {
        if (resultCode == Activity.RESULT_OK) {
                Bundle extras = data.getExtras();
                Product_ID.clear();
                assert extras != null;
                Product_ID = extras.getIntegerArrayList("Product_ID");
                SetProductData();
        }
    }  else if (requestCode == Popup_Selected_Result_Gift) {
            if (resultCode == Activity.RESULT_OK) {
                Bundle extras = data.getExtras();
                Gift_ID.clear();
                assert extras != null;
                Gift_ID = extras.getIntegerArrayList("Product_ID");
                hm_Gift = (HashMap<Integer, Integer>) extras
                        .getSerializable("Hash_Data");
                SetGiftData();
            }
        } else if (requestCode == Popup_Selected_Result_Sample) {
            if (resultCode == Activity.RESULT_OK) {
                Bundle extras = data.getExtras();
                Sample_ID.clear();
                assert extras != null;
                Sample_ID = extras.getIntegerArrayList("Product_ID");
                hm_Sample = (HashMap<Integer, Integer>) extras
                        .getSerializable("Hash_Data");
                SetSampleData();
            }
        }
}
    
0

There are 0 best solutions below