Hi,

I have one service that is running in the background and make a simple
scheduled (every 10 seconds) notification on the notification bar.
I'm trying to call the stopservice method, but the result is always
false and the service onDestroy() method is never called.

Any hint?

thanks

public class ServiceActivity extends Activity {

    /** Called when the activity is first created. */

   .....
   ....

  public void onCreate(Bundle savedInstanceState) {

       try{

        TestService.setMainActivity(this);

       }catch(Exception e){

           t.setText(e.getMessage());

       }

    }

@Override
    public void onStop() {
        super.onStop();
        Log.d("onStop:" , "stopping activity");
        Intent svc = new Intent(this,TestService.class);
                Boolean result = false;
                try {
                        result = stopService(svc);
                        Log.d("onStop:" , "stop service result: " + result);

                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }


    }

}
================================

public class TestService extends Service {

        private static Timer timer = new Timer();
        private static ServiceActivity ServAct;
        static long i=0;




        @Override
        public IBinder onBind(Intent intent) {
                return(null);
        }

        @Override
        public void onCreate() {
                super.onCreate();
                Log.d( "Servizio","onCreate" );
        }

    @Override
    public void onDestroy() {
          super.onDestroy();
          _shutdownService();

          Log.d( "Servizio","onDestroy" );
    }



    public static void setMainActivity(ServiceActivity activity) {

        ServAct = activity;

        Log.d("TestService","started!!");

                _startService();


        }

    private static void _startService() {

                  timer.scheduleAtFixedRate(

                      new TimerTask() {

                        public void run() {

                                update();

                        }

                      },

                      0,

                      10000);

                }

    public static void update(){

        i++;

        ServAct.setNotification("Test Service " + i, "Value = " + i);


        }

    private void _shutdownService() {
          if (timer != null) timer.cancel();
          Log.d(getClass().getSimpleName(), "Timer stopped!!!");
        }



}




-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to