Skip to content

Instantly share code, notes, and snippets.

@SeanSWatkins
Created February 6, 2013 12:51
Show Gist options
  • Select an option

  • Save SeanSWatkins/4722332 to your computer and use it in GitHub Desktop.

Select an option

Save SeanSWatkins/4722332 to your computer and use it in GitHub Desktop.
SomeService using a Timer
public class SomeService extends Service
{
public int fiveMinCounter = 0,twoMinCounter = 0;
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public void onCreate(){
Intent startActIntent = new Intent(context,Splash.class);
startActPending = PendingIntent.getActivity(context, 0,startActIntent, 0);
Notification noti = new NotificationCompat.Builder(
context).setContentTitle(getResources().getString(R.string.app_name))
.setSmallIcon(R.drawable.icon).setContentIntent(startAct)
.setWhen(System.currentTimeMillis())
.setContentText("Touch to open UI").getNotification();</pre>
this.startForeground(1,noti);
Timer timer = new Timer();
timer.schedule(new mTimerTask(),1000,1000);
}
public class mTimerTask extends TimerTask{
@Override
public void run(){
//Run some code here
fiveMinCounter++;
twoMinCounter++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment