Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.iimanager;
- import android.app.Activity;
- import android.app.AlarmManager;
- import android.app.PendingIntent;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.os.SystemClock;
- import android.view.Menu;
- import android.widget.Toast;
- public class IIManagerActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_iimanager);
- AlarmManager mgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
- Intent i=new Intent(this, SampleService.class);
- PendingIntent pi=PendingIntent.getService(this, 0, i, 0);
- mgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), AlarmManager.INTERVAL_FIFTEEN_MINUTES/900, pi);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.activity_iimanager, menu);
- return true;
- }
- }
- package com.example.iimanager;
- import android.app.IntentService;
- import android.app.Notification;
- import android.app.NotificationManager;
- import android.app.PendingIntent;
- import android.content.Context;
- import android.content.Intent;
- import android.widget.Toast;
- public class SampleService extends IntentService {
- public SampleService() {
- super("SimpleService");
- //Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();
- }
- @Override
- protected void onHandleIntent(Intent intent) {
- //do something
- Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();
- }
- }
- class CustomTimerTask extends TimerTask {
- private Context context;
- private Handler mHandler = new Handler();
- // Write Custom Constructor to pass Context
- public CustomTimerTask(Context con) {
- this.context = con;
- }
- @Override
- public void run() {
- new Thread(new Runnable() {
- @Override
- public void run() {
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();
- }
- });
- }
- }).start();
- }
- }
- public class Toaster extends Thread{
- public void run(){
- //Your code to loop
- thread.sleep(60000)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement