0

Here is some code for the idea of my problem:

@Override
public void onDestroy() {
    Log.e("onDestroy------------->", "onDestroy called");
    Toast.makeText(this, " onDestroy Started", Toast.LENGTH_LONG).show();
    super.onDestroy();
}

and

b2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            //startServiceManually();
            stopService(i);

        }
    });
Cœur
  • 37,241
  • 25
  • 195
  • 267
sameer balouria
  • 470
  • 6
  • 20
  • see this http://stackoverflow.com/questions/9665256/android-stopservice-in-another-activity – User11 May 15 '14 at 10:12

2 Answers2

0
try { 
stopService(new Intent(YOUR ACTIVITY NAME.this, YOUR SERVICE NAME.class));                                      
} catch (Exception e) {                                         e.printStackTrace();            
}
Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
0

Try either this...

  Intent i = new Intent(this, THE_SERVICE_NAME.class);
  stopService(i);

If that doesn't work the make sure you have an onDestroy in the service and if your using a notification the in onDestroy, put

 stopForeground(true);

Or just copy this...

 @Override
 public void onDestroy(){
  super.onDestroy();
  stopForeground(true);
}