Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6783169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:49:55+00:00 2026-05-26T16:49:55+00:00

package de.tablayoutexample; import java.util.List; import android.os.AsyncTask; import android.util.Log; public class CallWebServiceTask extends AsyncTask<String, String,

  • 0
package de.tablayoutexample;

import java.util.List;

import android.os.AsyncTask;
import android.util.Log;

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

    private PhotosActivity theActivity;

    public CallWebServiceTask(PhotosActivity theActivity){

        this.setTheActivity(theActivity);

    }

    @Override
    protected void onPreExecute(){

        PhotosActivity.showSpinner();

    }

    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub

        return PhotosActivity.getEventList();
    }
    @Override
   protected void onPostExecute(String result) {

        List<SingleEvent> thelist = PhotosActivity.parseJSONResponse(result);

    /*for(int i=0;i<thelist.size();i++){
        SingleEvent entry = thelist.get(i);

        Log.v("Finished", entry.getTitle());

    }*/

        theActivity.refreshListView(thelist);

        PhotosActivity.hideSpinner();



    }

    public PhotosActivity getTheActivity() {
        return theActivity;
    }

    public void setTheActivity(PhotosActivity theActivity) {
        this.theActivity = theActivity;
    }


}

I’m not entirely sure what I am doing, but I ended up writing the class above that works with my PhotosActivity class, which contains all the necessary methods that are called. However, what if I wanted to create an asynctask class that could be used for all of my activities? How would I do that? I tried changing all the PhotosActivity types to “Activity” but that doesnt seem to be all there is to it.

My question is, how would I make this class truly dynamic?

EDIT:

Here is my CustomActivity base class that includes the AsyncTask class inside:

package de.tablayoutexample;

import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;

public class CustomActivity extends Activity{

    public String getEventList() {
        // TODO Auto-generated method stub
        return null;
    }

    public Object parseJSONResponse(String result) {
        // TODO Auto-generated method stub
        return null;
    }

    public void showSpinner() {
        // TODO Auto-generated method stub

    }

    public void refreshListView(Object thelist) {
        // TODO Auto-generated method stub

    }

    public void hideSpinner() {
        // TODO Auto-generated method stub

    }

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

        private CustomActivity theActivity;

        public CallWebServiceTask(CustomActivity theActivity){

            this.setTheActivity(theActivity);

        }

        @Override
        protected void onPreExecute(){

            theActivity.showSpinner();

        }

        @Override
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            Log.i("ADASD","EXECUTED");
            return theActivity.getEventList();
        }
        @Override
       protected void onPostExecute(String result) {

            Object thelist = theActivity.parseJSONResponse(result);


            theActivity.refreshListView(thelist);

            theActivity.hideSpinner();



        }

        public CustomActivity getTheActivity() {
            return theActivity;
        }

        public void setTheActivity(CustomActivity theActivity) {
            this.theActivity = theActivity;
        }


    }




}

So everything is working correctly except for the parseJSONResponse method because the return type will be different for every Activity that uses this base class:

For example, my PhotosActivity returns a List of my SingleEvent object, which gson nicely makes for me.

public List<SingleEvent> parseJSONResponse(String jsonResponse) {

        //using gson, place all the json into the SingleEvent object and then into a List
        Type listType = new TypeToken<List<SingleEvent>>(){}.getType();  
        List<SingleEvent> events = new Gson().fromJson(jsonResponse, listType);


        return events;

    }

The problem is that the next Activity will use a different object to store my values. I don’t know how to deal with the different object types.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:49:56+00:00Added an answer on May 26, 2026 at 4:49 pm

    Be careful with the terms. “Dynamic” is a loaded word. this is basic OOD. Make the static methods of your PhotosActivity regular methods, and create a base class that all of your activities extend. Have a “doWork” method in those activities that the AsyncTask calls.

    there are better ways to do this kind of thing, but if its what you’re looking for, it’ll work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package vaannila; import java.util.ArrayList; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport { private String
package pkgPeople; import java.io.Serializable; import java.text.DecimalFormat; public class Person implements Serializable{ private String name;
package com.example.helloandroid; import java.io.File; import android.os.AsyncTask; import android.os.Environment; import android.widget.Toast; public class CheckTask extends
package { import flash.display.Sprite; public class test1 extends Sprite { private var tmp:Object; public
package myProg; import java.util.Scanner; public class oving4a { /** *Øving 4a. Aleksander Pettersen */
package net.learn2develop.PopularAttractions; import java.io.IOException; import java.util.List; import java.util.Locale; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController;
package com.example.android.home; import android.app.Activity; import android.os.Bundle; import android.widget.*; import android.view.*; public class HomeActivity extends
package pkg_2; import java.util.*; class shape{} class Rect extends shape{} class circle extends shape{}
package homework5; import java.io.*; import java.util.Arrays; public class Main { /** * @param args
package com.ewebapps; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.view.View; public class Dot extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.