Q:

Image Button state is needed in my service

So I have a service that is started when a button is clicked. When the service starts I disable the button that was clicked, but I want to enable it again once the service is finished. If I create an instance of the calling class in the service class, I get a null pointer exception. I have no idea how to enable the button again. If I do it just after I call the "stopService()" then the button just stays enabled. Please help. Thanks guys.
Code -> service class
package com.project.llb;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.widget.Toast;

public class SetupTimer extends Service
{
Handler handler;
runGraphics runG;
int timerCount = 0;
@Override
public IBinder onBind(Intent intent) 
{
    return null;
}//end onBind function

@Override
public void onCreate() 
{
    super.onCreate();

    handler = new Handler();
    timerCount++;
    handler.postDelayed(runnable, 1000);
}//end onCreate function

private Runnable runnable = new Runnable()
{
    public void run()
    {

        timerCount++;
        if (timerCount < 3)
        {
            handler.postDelayed(runnable, 1000);
        }//end if
        else
        {
            runG.polarCap1.setEnabled(true); //this will not work 
            handler.removeCallbacks(runnable);
        }//end else
    }//end run function
};//end runnable    

@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
    return Service.START_NOT_STICKY;
}//end onStartCommand function

}//end SetupTimer class

and here is my button function in the calling class:
polarCap1 = (ImageButton) findViewById(R.id.polarCapButton1);
polarCap1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{   

    //button cannot be clicked
    polarCap1.setEnabled(false);

    //start service for timer
    startService(new Intent(runGraphics.this, SetupTimer.class));

    //stop service for timer
    stopService(new Intent(runGraphics.this, SetupTimer.class));

    //button can be clicked again
    //polarCap1.setEnabled(true);

}//end onClick function         
});//end setOnClickListener

and this is my logcat:
05-23 09:58:06.986: E/AndroidRuntime(31852): FATAL EXCEPTION: main
05-23 09:58:06.986: E/AndroidRuntime(31852): java.lang.NullPointerException
05-23 09:58:06.986: E/AndroidRuntime(31852):    at com.project.llb.SetupTimer$1.run(SetupTimer.java:64)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at android.os.Handler.handleCallback(Handler.java:587)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at android.os.Looper.loop(Looper.java:130)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at android.app.ActivityThread.main(ActivityThread.java:3806)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at java.lang.reflect.Method.invokeNative(Native Method)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at java.lang.reflect.Method.invoke(Method.java:507)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-23 09:58:06.986: E/AndroidRuntime(31852):    at dalvik.system.NativeStart.main(Native Method)

A:

Using the local broadcast to send the status of the button worked.

