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 7845217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:09:21+00:00 2026-06-02T17:09:21+00:00

Quick Question, i am looking to update a list view from an Async task

  • 0

Quick Question, i am looking to update a list view from an Async task in a different activity than the task was spawned from. My question is in regards updating the adapter in the other activity, how would i go about accessing the other activities adapter so i can add to it (using adapter.add(item);) and notify the adapter of change to update the list in the other activity (adapter.notifyChange();) ?

Here is connection task:

public class ConnectionTask extends AsyncTask<Context, String, Void> {

private String mText;
private Context mContext;
private int NOTIFICATION_ID = 1;
private Notification mNotification;
private NotificationManager mNotificationManager;




@SuppressWarnings("unused")
private NotificationActivity noteact = new NotificationActivity();


public ConnectionTask(Context context){

    this.mContext = context;

    //Get the notification manager
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);



}








@Override
protected void onPreExecute() {

    Log.i("PushNote", "onPreExecute");
}






public void setmText(String mText){
    this.mText = mText;
}


public String getmText(){
    return mText;
}


@Override
protected Void doInBackground(Context... params) {
    Socket clientSocket = null;
    //Creates the is connected boolean and sets it to false
    boolean connected = false;



    String ipaddr = getmText();

    // define a writer and a reader, so that we can interact with the
    // Server
    BufferedReader inFromServer = null;



    InetAddress addr = null;
    try {

        addr = InetAddress.getByName(ipaddr);
        } catch (UnknownHostException e1) {
        // TODO Auto-generated catch block
        publishProgress(e1.toString());
        e1.printStackTrace();
    }



    // Dynamically find IP of current Localhost
    String HostName = addr.getHostName();



    int port = 6789;


    try {
        // Lets try and instantiate our client and define a port number.


        clientSocket = new Socket(HostName, port);
        //  once the client is connected sets the isConnected boolean to true
        connected = true;



        // lets also link the writer and reader to the client.
        inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

        // make sure to always catch any exceptions that may occur.
        } catch (UnknownHostException e) {
        // always print error to "System.err"
        publishProgress(e.toString());
        // 2 different types of exceptions, so we want to output meaning
        // information for both.
        } catch (IOException e) {
        publishProgress(e.toString());
    }



    // Boolean which indicates if the client is connected or not,
    // if connected it takes in the next line of user input and returns the servers response.
    while (connected) {



        // Send the user message to the server




        // read the reply from the server
        String reply = null;
        try {
            reply = inFromServer.readLine();
            } catch (IOException e) {
            // TODO Auto-generated catch block

            e.printStackTrace();
            publishProgress("Failed to connect." );
            System.exit(1);

        }

        if (reply != null){

            // output the reply as a notification
            if (isCancelled()){
                break;
            }
            publishProgress(reply);


            } else {
            try {
                inFromServer.close();
                } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                publishProgress(e.toString());
                System.exit(1);
            } // the reader
            try {
                clientSocket.close();
                } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                publishProgress(e.toString());
                System.exit(1);
            } // and the client socket
        }

    }


    // always remember to close all connections.






    // TODO Auto-generated method stub
    return null;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void onProgressUpdate(String... item) {

    Notification("Push2Note: ", item[0]);






}




public void Notification(String contentTitle, String contentText) {

    //Build the notification using Notification.Builder
    long[] vibrate = {0,100,200,300};

    PendingIntent pendingIntent;
    Intent intent = new Intent();
    intent.setClass(mContext,NotificationActivity.class);
    pendingIntent =  PendingIntent.getActivity(mContext, 0, intent, 0);


    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
    .setSmallIcon(android.R.drawable.presence_online)
    .setAutoCancel(true)
    .setVibrate(vibrate)
    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
    .setContentIntent(pendingIntent)
    .setContentTitle(contentTitle)
    .setContentText(contentText);

    //Get current notification
    mNotification = builder.getNotification();



    //Show the notification
    mNotificationManager.notify(NOTIFICATION_ID, mNotification);
}

}

Here is the activity im looking to populate:

public class NotificationActivity extends ListActivity {

    /** Called when the activity is first created. */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notifications);

        setListAdapter(new ArrayAdapter(this,
                android.R.layout.simple_list_item_checked, new ArrayList()));

    }

}

Ive read trough similar questions and have heard tell of use of global adapters but have no idea how i can implement such a thing.

This is the last piece of the puzzle which remains a mystery to me with my applications and any help on the matter would be greatly appreciated.

Thanks for your time,

All the best.

  • 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-06-02T17:09:22+00:00Added an answer on June 2, 2026 at 5:09 pm

    You should have an ArrayList which the Adapter uses, that you can access from the Activity, which modifies it.
    It can be either public static or can be accessed via getter from the Activity which is passed as parameter to the Activity.

    When you accessed the ArrayList, you can do whatever you want and then call invalidateViews() on the ListView for the other Activity.

    items.remove(position);
    MainListActivity.listView.invalidateViews();
    

    Now, when your Adapter calls its getView() method, it gets the list which you updated.

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

Sidebar

Related Questions

quick and very basic newbie question. If i have list of dictionaries looking like
Just a quick and simple question: I am using php and am looking to
A quick question from a beginner. I'm doing an App for the iPhone and
Quick question, looking for some recommendations. I have a site that will be requesting
Quick question Re: Implementation of RowVersion. I am looking to include it in my
quick question here. I'm looking for a way to populate my JQuery search box,
just a quick question while looking at Clojure.... Given the following REPL Session: Clojure
Quick question, I'm looking for a python function that performs the equivalent job that
Quick embrassing question. I have been looking for a PHP function that would calculate
quick question, I've been looking for a simple logging tool for AS3 projects (I

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.