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

  • SEARCH
  • Home
  • 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 7499563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:51:58+00:00 2026-05-29T19:51:58+00:00

I want to pass a custom made vector object containing data from background service

  • 0

I want to pass a custom made vector object containing data from background service to an activity in order to updating UI of that activity.
I am not able to pass my data via intent. Please assist me what i need to do..

Following is the code snippet that i am using. In below code I want to pass article list to an activity.

Vector<RowData> getArticleLog() throws JSONException{

    Vector<RowData> articleList = new Vector<RowData>();

    RowData rd;
    InputStream is = null;
    String result = null;
    JSONArray jarray = new JSONArray();

    //Add data to be send.
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("article_title", "Flying Horse"));

    try {

        HttpClient httpclient = new DefaultHttpClient();

        // for local server xampp
        HttpPost httppost = new HttpPost("http://10.0.2.2/groupbook/return_article_log.php");

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);

        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        Log.i("postData", response.getStatusLine().toString());

    } catch (Exception e) {
        Log.e(TAG, "json error : " + e.toString());
    }
    //convert response to string
    try {
         BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
         StringBuilder sb = new StringBuilder();
         String line = null;
         while ((line = reader.readLine()) != null) {
                 sb.append(line + "\n");
         }
         is.close();

         result=sb.toString();
    } catch (Exception e) {
         Log.e(TAG, "Error converting result "+e.toString());
    }

    try {
        jarray = new JSONArray(result);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    //return jArray in the form of Array list;
    JSONObject rowElement = null;
    int viewers = 0;
    int votes = 0;

    for (int i = 0; i < jarray.length(); i++) {
        rowElement = jarray.getJSONObject(i);

        viewers = rowElement.getInt("viewers");
        votes = rowElement.getInt("votes");

        rd = new RowData(i, 
                rowElement.getString("article_title"), 
                Integer.toString(i), 
                rowElement.getString("last_post_by"),
                "2 hours", 
                rowElement.getString("catagory_tag"), 
                Integer.toString(viewers), 
                rowElement.getString("privacy_tag"), 
                Integer.toString(votes), 
                rowElement.getString("catagory_title"));
        articleList.add(rd);
    }

    return articleList;
} 

RowData class is as follows :

public class RowData {

protected int mId;
public String articleTitle;
public String articleCounter;
public String lastPostBy;
public String updatedTime;
public String catagoryTag;
public String viewingNow;
public String privacyTag;
public String votes;
public String catagoryTitle;

public RowData(int mId, String articleTitle, String articleCounter,
        String lastPostBy, String updatedTime, String catagoryTag,
        String viewingNow, String privacyTag, String votes,
        String catagoryTitle) {
    this.mId = mId;
    this.articleTitle = articleTitle;
    this.articleCounter = articleCounter;
    this.lastPostBy = lastPostBy;
    this.updatedTime = updatedTime;
    this.catagoryTag = catagoryTag;
    this.viewingNow = viewingNow;
    this.privacyTag = privacyTag;
    this.votes = votes;
    this.catagoryTitle = catagoryTitle;
}
}

Is following way is right way??

private void DisplayingInfo() throws JSONException{
    Log.d(TAG, "entered DisplayLoggingInfo");
    intent.putExtra("articleLog", getArticleLog());
    sendBroadcast(intent);
}
  • 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-29T19:52:00+00:00Added an answer on May 29, 2026 at 7:52 pm

    One thing you can do is to make your custom class implement Serializable (or Parcelable), send the serializable object with putExtra() method to the activity and use getSerializableExtra() on your activity to get it.


    Edit 1:
    a quick example:

    In your custom class:

    import java.io.Serializable;
    
    @SuppressWarnings("serial")
    public class YourCustomVectorClass implements Serializable {
        // ...
    }
    

    In your service where you want to start the activity:

    Intent intent = new Intent(yourContext, yourActivity.class);
    intent.putExtra("theNameOfTheObject", yourObject);
    startActivity(intent);
    

    In your activity:

    YourCustomVectorClass yourVector = (YourCustomVectorClass) getIntent().getSerializableExtra("theNameOfTheObject");
    

    Edit 2: After reading the question again, I realized that you’re passing a Vector of RowData objects to your Activity.

    Since Java Vector class implements Serializable, I think you shouldn’t do anything but passing the vector to the activity using putExtra() and get it with getSerializableExtra() on the Activity.

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

Sidebar

Related Questions

I am trying to pass custom event data from 1 class to another class...here
I pass the custom data type of C# struct and now I want to
I want to pass a serialized json object and returned it within custom Html
I know how to pass data from one activity to another. But what I
Is that possible? I want to pass my custom color as a parameter and
I have made a custom object called students that has two nsstring object. One
How can I pass custom data to the jQuery event handler, specifically from the
I want to pass an integer value to a form in .Net so that
Here is my custom module using hook, Assume if I want to pass argument
I want to detach some XmlElement from one XmlDocument in order to insert it

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.