0

I am very new to services

In my application there is a 2 button "start" and "stop"

if user press a start button then i want to start a service that can run even after the application is closed

and when user again open the application if he press the button stop then i want to stop the service that i have created and run before

So far i have created a service and i am returning the START_STICKY from OnStartCommand method and service runs even after i close the app

But when i again open the app and try to stop by pressing button stop it is not stopping i hope it is again recreating

Please help me if anyone knows about this....

Thanks in Advance

Sandy
  • 985
  • 5
  • 13
  • hmm, try using alarm manager with service class? look here: http://stackoverflow.com/questions/1082437/android-alarmmanager , https://www.google.co.il/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCsQFjAA&url=http%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fapp%2FAlarmManager.html&ei=fgNeU-e3EqT07AbJ1ICQAw&usg=AFQjCNE1Xy99Kn5P4zGr8t2xbOOAlbSMQQ&sig2=ZLJubG6DO5qQzilf9Fcymw&bvm=bv.65397613,d.ZGU – SacreDeveloper Apr 28 '14 at 07:30
  • Try using debugger and logcat to see what happens when you stop service. If callbacks method are not being called (like onDestroy()) then there may be some coding issue. If you paste your code here, maybe that would be helpful – user2430771 Mar 26 '15 at 22:15

1 Answers1

0
Intent i = new Intent(Activityclass.this, Serviceclass.class);
start.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

startService(i);
            }
        });
stop.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

stopService(i);
            }
        });
nawaab saab
  • 1,892
  • 2
  • 20
  • 36
  • still not working do you have any sample that returns a start_sticky from onStartCommand Method and you can still able to stop it – Sandy Apr 28 '14 at 09:38
  • what you actually want to do? – nawaab saab Apr 28 '14 at 10:01
  • i want to download a file that will work even if the app close and suppose after open app user want to stop download he can do and also file can be multiples that i am downloading simultaneously – Sandy Apr 28 '14 at 12:50