Created
February 6, 2013 12:51
-
-
Save SeanSWatkins/4722332 to your computer and use it in GitHub Desktop.
SomeService using a Timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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