I called the stopService() method from the calling class when the calling activity exits, and the service does not stop. It keeps on running in the background and can thus be a hastle to the end user. Any help would be greatly appreciated..

Code:

```
public class MainActivity2 extends ActionBarActivity {
ListView listView;
static int cnt1=0;
static int bob=1;
RelativeLayout background2;

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main_activity2);

background2 = (RelativeLayout) findViewById(R.id.background);
int num = 0;
final ListView theListView = (ListView) findViewById(R.id.listView);
Intent calledActivity = getIntent();
final List pe = calledActivity.getExtras().getStringArrayList("Caller1");

String[] s = new String[pe.size()];
for (int i = 0; i < pe.size(); i++) {
    s[i] = (String) pe.get(i);
}

final ListAdapter theAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, pe);
theListView.setAdapter(theAdapter);
final int cnt = 1;
Intent mIntent = new Intent(this, MyService.class);
mIntent.putStringArrayListExtra("Caller2", (ArrayList<String>) pe);
mIntent.putExtra("intCall",bob);
startService( mIntent);

theListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String s1 = String.valueOf(parent.getItemAtPosition(position));
        pe.remove(s1);
        if (pe.size() == 0) {
            stopService(new Intent(MainActivity2.this, MyService.class));

            Intent goback;
            goback = new Intent(MainActivity2.this, MainActivity.class);
            startActivity(goback);
        }
        ((BaseAdapter) theAdapter).notifyDataSetChanged();

    }
});
}

```

MY SERVICE CLASS:

```
public class MyService extends Service {
public MyService() {
}

@Override
public IBinder onBind(Intent arg0) {

return null;}

@Override
public void onCreate() {

    Toast.makeText(this, "Congrats! Blocker Created", Toast.LENGTH_LONG).show();

}

@Override
public void onStart(final Intent intent, int startId) {
int i=0;

    Timer t = new Timer();

    t.scheduleAtFixedRate(new TimerTask() {

                              @Override
                              public void run() {
                                  ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
                                  List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);

                                  ActivityManager.RunningTaskInfo ar = tasks.get(0);
                                  String activityOnTop=ar.topActivity.getClassName();
                                  Intent lockIntent = new Intent(MyService.this, LockScreen.class);
                                  lockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                  ComponentName componentInfo = tasks.get(0).topActivity;
                                  if(!componentInfo.getPackageName().equals("com.example.epiclapser.noprocrastinate"))
                                  {

                                        startActivity(lockIntent);
                                      Log.v("iwashere", "-- ACTIVITY --");
                                  }
                              }

                          },
            0,

            1000);

    Toast.makeText(this, "My Blocker Started", Toast.LENGTH_LONG).show();

}

@Override
public void onDestroy() {
    Toast.makeText(this, "MyService Stopped", Toast.LENGTH_LONG).show();
    super.onDestroy();
}

}

```