Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package com.example.iimanager;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlarmManager;
  5. import android.app.PendingIntent;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.os.Bundle;
  9. import android.os.SystemClock;
  10. import android.view.Menu;
  11. import android.widget.Toast;
  12.  
  13. public class IIManagerActivity extends Activity {
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_iimanager);
  19. AlarmManager mgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
  20. Intent i=new Intent(this, SampleService.class);
  21. PendingIntent pi=PendingIntent.getService(this, 0, i, 0);
  22. mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_FIFTEEN_MINUTES/900, pi);
  23. }
  24.  
  25. @Override
  26. public boolean onCreateOptionsMenu(Menu menu) {
  27. // Inflate the menu; this adds items to the action bar if it is present.
  28. getMenuInflater().inflate(R.menu.activity_iimanager, menu);
  29. return true;
  30. }
  31. }
  32.  
  33. package com.example.iimanager;
  34.  
  35. import android.app.IntentService;
  36. import android.app.Notification;
  37. import android.app.NotificationManager;
  38. import android.app.PendingIntent;
  39. import android.content.Context;
  40. import android.content.Intent;
  41. import android.widget.Toast;
  42.  
  43. public class SampleService extends IntentService {
  44.  
  45. public SampleService() {
  46. super("SimpleService");
  47. //Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();
  48. }
  49.  
  50. @Override
  51. protected void onHandleIntent(Intent intent) {
  52. //do something
  53. Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();
  54. }
  55. }
  56.  
  57. class CustomTimerTask extends TimerTask {
  58. private Context context;
  59. private Handler mHandler = new Handler();
  60. // Write Custom Constructor to pass Context
  61. public CustomTimerTask(Context con) {
  62. this.context = con;
  63. }
  64.  
  65. @Override
  66. public void run() {
  67. new Thread(new Runnable() {
  68. @Override
  69. public void run() {
  70. mHandler.post(new Runnable() {
  71. @Override
  72. public void run() {
  73. Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();
  74. }
  75. });
  76. }
  77. }).start();
  78.  
  79. }
  80.  
  81. }
  82.  
  83. public class Toaster extends Thread{
  84. public void run(){
  85. //Your code to loop
  86.  
  87. thread.sleep(60000)
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement