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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:07:59+00:00 2026-06-04T08:07:59+00:00

I am creating an Instant Messenger for android using asmack. I have started a

  • 0

I am creating an Instant Messenger for android using asmack.
I have started a Chat service which connects to xmpp server.
the service connects to xmpp server and i am getting the roster and presence.
but now i have to update the UI and pass the list of account objects from service to activity. i have come across Parcelable and serializable.
i can not figure out what is the correct way for this service.
Can some one provide some code samples where i can do the same.

Thanks

  • 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-04T08:08:01+00:00Added an answer on June 4, 2026 at 8:08 am

    you’re making a nice app. I don’t know more about smack but I know how to pass objects from service to Activity. You can make AIDL for your service. AIDL’ll pass your service objects to activity. And then you can update your Activity UI. This link might be helpful to you!

    First you have to make .aidl file using your editor and save this file on your desktop. AIDL is just like an interface nothing else. Like, ObjectFromService2Activity.aidl

    package com.yourproject.something
    
    // Declare the interface.
    interface ObjectFromService2Activity {
        // specify your methods 
        // which return type is object [whatever you want JSONObject]
        JSONObject getObjectFromService();
    
    }
    

    Now copy this file and paste it to your project folder and the ADT plugin will generate the ObjectFromService2Activity interface and stub automatically in gen/ folder.

    The Android SDK also includes a (command line) compiler aidl (in the tools/ directory) that you can use to generate the java code in case you don’t use Eclipse.

    Override obBind() method in your service. Like, Service1.java

    public class Service1 extends Service {
    private JSONObject jsonObject;
    
    @Override
    public void onCreate() {
      super.onCreate();
      Log.d(TAG, "onCreate()");
      jsonObject = new JSONObject();
    }
    
    @Override
    public IBinder onBind(Intent intent) {
    
    return new ObjectFromService2Activity.Stub() {
      /**
       * Implementation of the getObjectFromService() method
       */
      public JSONObject getObjectFromService(){
        //return your_object;
        return jsonObject;
      }
     };
    }
    @Override
    public void onDestroy() {
       super.onDestroy();
       Log.d(TAG, "onDestroy()");
     }
    }
    

    Start your service using your activity or where you want to start this service and make ServiceConnection. Like,

    Service1 s1;
    private ServiceConnection mConnection = new ServiceConnection() {
        // Called when the connection with the service is established
        public void onServiceConnected(ComponentName className, IBinder service) {
            // Following the example above for an AIDL interface,
            // this gets an instance of the IRemoteInterface, which we can use to call on the service
            s1 = ObjectFromService2Activity.Stub.asInterface(service);
        }
    
        // Called when the connection with the service disconnects unexpectedly
        public void onServiceDisconnected(ComponentName className) {
            Log.e(TAG, "Service has unexpectedly disconnected");
            s1 = null;
        }
    };
    

    Using object of ObjectFromService2Activity you can access method s1.getObjectFromService() will return JSONObject. More Help Fun!

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

Sidebar

Related Questions

Creating a server-side socket will fail if I'm trying to use the same port
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating a simple RPG game, first time using XNA. Trying to get my character
When creating a new service in a WCF service project, Visual Studio will automatically
Creating an installer for possible remote systems so that if they do not have
Creating a table without tbody using javascript createElement/appendChild will not add tbody in Firebug
Creating sprite sheets aka texture atlases rather than using many hundres of individual images
Creating the closure is easy but using it is confusing for me. Here is
Creating an index MySQL After I have added the FULLTEXT index, how do I
Creating a simple TCP server based on examples but still do not get how

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.