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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:03:35+00:00 2026-05-30T00:03:35+00:00

I have created a simple service which will increment a counter and log it.

  • 0

I have created a simple service which will increment a counter and log it.

    public class AudioService extends Service {
    int i=0;
    private final IAudioInterface.Stub mBinder = new IAudioInterface.Stub() {

            public int getI()
            {
                return i;
            }

        };

        @Override
        public IBinder onBind(Intent intent) {

            Log.d("onBind from service","****");

            return mBinder;
        }

        @Override
        public void onCreate() {

            super.onCreate();
            Log.d("onCreate from service","***");
            Log.d("i=","="+i);
            i=i+1;


        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            Log.d("OnDestroy Called from service","***");


        }

        public void onStartCommand(Intent intent, int startId) {
            super.onStart(intent, startId); 
            Log.d("onStartCommand from service","***");

        }

        @Override
        public boolean onUnbind(Intent intent) {
            Log.d("onUnbind from service","***");
        return super.onUnbind(intent);
        }

i am incrementing the i value in the oncreate method of he service.

The Client Activity is as shown below

 public class AidlInterfaceServiceActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */

private static final String TAG = "Audio:Service";
IAudioInterface mService = null;
boolean connected = false;
ServiceConnection mConnection  = new ServiceConnection(){

    public void onServiceConnected(ComponentName arg0, IBinder service) {
        // TODO Auto-generated method stub
        connected = true;
        Log.d("Service connected","**");
        mService = IAudioInterface.Stub.asInterface(service);

        try {
            Log.d("i from client","="+mService.getI());
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public void onServiceDisconnected(ComponentName arg0) {
        // TODO Auto-generated method stub
        Log.i(TAG, "Service disConnected");
        connected = false;
        mService= null;
    }
 };


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.d("on created ","**********");

    Intent music = new Intent();
    music.setClass(this,AudioService.class);
    startService(music);
    bindService(music, mConnection, Context.BIND_AUTO_CREATE);


}

The AIDL file is as below

interface IAudioInterface
{

    int getI();
}

The problem is when i run the client activity every time the value of i is “0”.
i value is not getting incremented.

I have these queries.
1.what happens when the service is started multiple time.
2.what happens when the service is bounded multiple times.
3.what happens to the data members inside the service class when it is started multiple times.Does those data members get reinitialized.

I am really confused ..Any one please help.

  • 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-30T00:03:37+00:00Added an answer on May 30, 2026 at 12:03 am

    Does it help if you declare your counter variable as static?

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

Sidebar

Related Questions

i have created a simple public ref class in the vc++ project, which is
I have created a simple wcf service which used the WCF Service Library template.
I have created a simple WCF (.NET 3.5) service which defines 10 contracts which
I have created a simple windows service that periodically checks a remote database via
I have created a simple web-service using Java. i want to load jars related
I have created a simple Asp.Net custom control which automatically combines all the correct
I have a simple class called Job with a public ctor and public function
i am having a very simple problem. I have created an activity in which
Could someone help me on this, I have created simple web services using axis2
How to manually create Friendly URLs? (PHP) So I have created simple php file

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.