```
public class MainActivity {
        private MyListViewHelper mTimelineHelper;

        @Override
        protected void onCreate(Bundle savedInstanceState) {

        mListViewHelper = new MyListViewHelper(); 
        mListViewHelper.createListView();

        startService(new Intent(this, MyService.class));
}
}

```

MyService class:

```
    public class MyService extends Service {

        private int mCount = 0;

        public static final long NOTIFY_INTERVAL = 10 * 1000;

        private static MyListViewHelper mListViewHelper;

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

        @Override
        public void onCreate() {
            // cancel if already existed
            if (mTimer != null) {
                mTimer.cancel();
            } else {
                // recreate new
                mTimer = new Timer();
            }

            // schedule task
            mTimer.scheduleAtFixedRate(new TimeDisplayTimerTask(), 0, NOTIFY_INTERVAL);

        }

        @Override
        public void onDestroy() {
            mTimer.cancel();
        }

        private class TimeDisplayTimerTask extends TimerTask implements LocationListener {

            @Override
            public void run() {

                mHandler.post(new Runnable() {

                    @Override
                    public void run() {
                    //DO SOMETHING HERE
                    ...........
                    mCount++;
                    if(mCount==4){
                       mListViewHelper = new MyListViewHelper()
                       mListViewHelper.addItemToList("ABCD");
                    } 
                }

                });
        public boolean isMainActivityRunning(string packageName) {
             ActivityManager activityManager = (ActivityManager)getSystemService (Context.ACTIVITY_SERVICE);
             List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(Integer.MAX_VALUE); 

             for (int i = 0; i < tasksInfo.size(); i++) {
                    if(tasksInfo.get(i).baseActivity.getPackageName.toString().equals(packageName)
                  return true;
                  }

          return false;
          }     
        }
    }

```

MyListViewHelper class:

```
public class MyListViewHelper {
    private ListView mListView;
    private ArrayList<String> mArrayList;

    public MyListViewHelper () {
    }

    public void createListView(){
        mArrayList = new ArrayList<String>();
        mListView = (ListView) activity.findViewById(R.id.listView1);
        // I make a short version,so we suppose adapter is already prepared here
        mListView.setadapter(adapter);
    }

    public void addItemToList(String myString){
        mArrayList.add(myString);
        adapter.notifiDateSetChanged();
}
 }

```

What I want is for every 10 seconds, service will do something, and then if it do that 4 times, I will add one item to ListView. I forgot to save logcat before change it back to the time before I edited, so there is no logcat, sorry for that. But I'm pretty sure there is nothing wrong with others and the problem is just somewhere in the code above since I'm leanring Android and I don't have much knowledge about Service. Please teach me to fix that!