How to get string from async task and do in background

David

I am new to async tasks but I need to get a string from async task that is done in the background method for example

AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                try {

                    final MobileServiceList<AppDirectory> result =
                            mDirectoryTable.where().field("Family_Id").eq(11).execute().get();
                    for (AppDirectory item : result) {
                        //this is the string that I need to return
                         String neededstring = item.getheadofhousehold;
                    }
                } catch (final Exception e) {

                }
                return null;
            }
        };
//I need "neededstring" to equal result
        String result = task.execute();
Rusheel Jain

2 ways:

One is to use Interface as explained here: https://stackoverflow.com/a/12575319/1750013

Other one (quick and dirty), make a getters/setters in your Activity. In your onPostExecute(), set this string into the setter method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get value returned from async Task<string> function(); in C#

From Dev

submitting registration crashes at do in background of async task

From Dev

How to get returned value of async Task<string> method name()?

From Dev

C# How do I get string from Task<string> after a web request?

From Dev

C# How do I get string from Task<string> after a web request?

From Dev

How do I hold the Async Task from executing before the user input is stored in a variable that is required by the Async Task

From Dev

How do i return a result from a async task

From Dev

How to get result from async Task<> when I cannot Run()?

From Dev

How to proceed with Task, await and async in background

From Dev

How to get background task status from parent window in PowerShell

From Dev

How to escape from async Task

From Dev

How to set a higher task priority to a Parallel.Async background task?

From Dev

Async Task not running in background?

From Dev

Async Task not running in background?

From Dev

Get value from Async task in Activity

From Dev

How do I declare a generic async Task?

From Dev

How to get results of Async task in Android

From Dev

How to get predecessor id from task predecessor string?

From Dev

How to return a List of objects from an async task

From Dev

how to access to textbox from async Task

From Dev

How do I get the result from this async function?

From Dev

When does a background task get aborted because of "ResourceRevocation", and how do I prevent it?

From Dev

Running an async background task in Tornado

From Dev

How can I use a method async Task<string> and return string, and then how do I pass a delegate for that method to a constructor and use it later?

From Dev

How to create Async Task loading back ground while get data from data base

From Dev

How to kill background task from another session?

From Dev

How to open the app from the background task in iOS?

From Dev

how do I get rid of random background grid from arrangeGrob

From Java

How do you get a string from a MemoryStream?

Related Related

  1. 1

    How to get value returned from async Task<string> function(); in C#

  2. 2

    submitting registration crashes at do in background of async task

  3. 3

    How to get returned value of async Task<string> method name()?

  4. 4

    C# How do I get string from Task<string> after a web request?

  5. 5

    C# How do I get string from Task<string> after a web request?

  6. 6

    How do I hold the Async Task from executing before the user input is stored in a variable that is required by the Async Task

  7. 7

    How do i return a result from a async task

  8. 8

    How to get result from async Task<> when I cannot Run()?

  9. 9

    How to proceed with Task, await and async in background

  10. 10

    How to get background task status from parent window in PowerShell

  11. 11

    How to escape from async Task

  12. 12

    How to set a higher task priority to a Parallel.Async background task?

  13. 13

    Async Task not running in background?

  14. 14

    Async Task not running in background?

  15. 15

    Get value from Async task in Activity

  16. 16

    How do I declare a generic async Task?

  17. 17

    How to get results of Async task in Android

  18. 18

    How to get predecessor id from task predecessor string?

  19. 19

    How to return a List of objects from an async task

  20. 20

    how to access to textbox from async Task

  21. 21

    How do I get the result from this async function?

  22. 22

    When does a background task get aborted because of "ResourceRevocation", and how do I prevent it?

  23. 23

    Running an async background task in Tornado

  24. 24

    How can I use a method async Task<string> and return string, and then how do I pass a delegate for that method to a constructor and use it later?

  25. 25

    How to create Async Task loading back ground while get data from data base

  26. 26

    How to kill background task from another session?

  27. 27

    How to open the app from the background task in iOS?

  28. 28

    how do I get rid of random background grid from arrangeGrob

  29. 29

    How do you get a string from a MemoryStream?

HotTag

Archive