Home Can't set activity's variable from class method
Reply: 0

Can't set activity's variable from class method

user1753 Published in April 27, 2018, 6:41 am

Note: I'm not doing great with terminology as it's my first go on object-oriented programming and android studio.

In the android studio, I have created a class for a JSON fetching task. (I don't include the do in background override).

public class jsonTasks extends AsyncTask<String, String, String> {

public interface AsyncResponse {
    void processFinish(String output);

private AsyncResponse delegate = null;

jsonTasks(AsyncResponse delegate){
    this.delegate = delegate;

protected void onPostExecute(String result) {

In my activity now:

public class activity extends Activity {
    // in here I've declared the string variable
    String valuableInfo;

    jsonTasks asyncTask = new jsonTasks(new jsonTasks.AsyncResponse() {

        public void processFinish(String output) {
            String TAG = activity.class.getSimpleName();
            JSONObject info;

            //i do stuff with the json here
            //i set the textboxes normally

            //but setting the string valuableInfo is not working
            valuableInfo = "info I took from json operation"

    // and here I execute

    jsonTasks asyncTask2 = new .... {
    asyncTask2.execute("https://example.com/" + valuableInfo);

Where I want to use that variable is in another "asyncTask2" that with use the valuableInfo on the URL to continue fetching.

The variable is always null when I run the second "asyncTask2".

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303046 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO