private void fetchData()

in AccountTransferApi/app/src/main/java/com/google/accounttransfer/sample/MainActivity.java [83:113]


    private void fetchData() {
        // The logic can be modified according to your need.
        sharedPreferences = getSharedPreferences(SHARED_PREF, MODE_PRIVATE);
        firstTime = sharedPreferences.getBoolean(KEY_FIRST_TIME, true);
        if (firstTime) {
            Log.v(TAG, "Fetching account info from API");
            AccountTransferClient client = AccountTransfer.getAccountTransferClient(this);
            final Task<byte[]> transferBytes = client.retrieveData(ACCOUNT_TYPE);
            transferBytes.addOnCompleteListener(this, new OnCompleteListener<byte[]>() {
                @Override
                public void onComplete(@NonNull Task<byte[]> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "Success retrieving data. Importing it.");
                        try {
                            AccountTransferUtil.importAccounts(task.getResult(), MainActivity.this);
                        } catch (JSONException e) {
                            Log.e(TAG, "Encountered failure while retrieving data", e);
                            return;
                        }
                        populateAccountTextView();
                    } else {
                        // No need to notify API about failure, as it's running outside setup of
                        // device.
                        Log.e(TAG, "Encountered failure while retrieving data", task.getException());
                    }
                    // Don't try the next time
                    sharedPreferences.edit().putBoolean(KEY_FIRST_TIME, false).apply();
                }
            });
        }
    }