Skip to content Skip to sidebar Skip to footer

How Can I Create Asynctask Of My Gettotalincomeamount() Which Is An Integer Type Function In My Incomedao Class

I want to get total income amount from my Income table which have Amount table @ColumnInfo(name = 'Amount') private int amount; And in my IncomeDao I've @Query('SELECT SUM(

Solution 1:

Try below code,

You will get amount in doInBackgroud method from database, after geting value you will get call in onPostExecute method. If you have global variable then you can directly set value in doInBackgroud method.

private void getTotalIncomeAmount() {
        class TotalIncomeAmountAsyncTask extends AsyncTask<Void, Void, Integer> {

            @Override
            protected Integer doInBackground(Void... voids) {
             
                Integer value = DatabaseClient.getInstance(getApplicationContext()).getAppDatabase()
                        .taskDao()
                        .getTotalIncomeAmount();
                return value;
            }

            @Override
            protected void onPostExecute(Integer value) {
                super.onPostExecute(value);
                //
            }
        }
        TotalIncomeAmountAsyncTask totalIncome = new TotalIncomeAmountAsyncTask();
        totalIncome.execute();
    }

Post a Comment for "How Can I Create Asynctask Of My Gettotalincomeamount() Which Is An Integer Type Function In My Incomedao Class"