[Solved] How to give notification after every minute....

Put your problem here if it does not fit any of the other categories.

[Solved] How to give notification after every minute....

Postby Sachin » Thu Dec 27, 2007 1:12 pm

:)
Interested in learning new kind of a thing...
Sachin
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Dec 27, 2007 12:15 pm
Location: Pune.

Top

Postby daroN » Thu Dec 27, 2007 1:40 pm

daroN
Junior Developer
Junior Developer
 
Posts: 15
Joined: Fri Dec 14, 2007 7:58 pm

Postby Lex » Thu Dec 27, 2007 5:08 pm

I would create a service, I didnt test this code completely but it should work, not sure if its the most elegant way. If anyone knows a better one...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class Servicetest extends Service implements Runnable
  2.  
  3. {
  4.  
  5.  
  6.  
  7.        
  8.  
  9.          @Override
  10.  
  11.             protected void onCreate()
  12.  
  13.             {
  14.  
  15.                         Thread thr = new Thread (null, this, "Servicetest");
  16.  
  17.                         thr.start();
  18.  
  19.             }
  20.  
  21.  
  22.  
  23.          public void run()
  24.  
  25.                 {
  26.  
  27.                         for(;;)
  28.  
  29.                         {
  30.  
  31.                                 try
  32.  
  33.                                 {
  34.  
  35.                                         NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  36.  
  37.                                         mNM.notifyWithText(1, "You called me ?", 2, null);
  38.  
  39.                                         Thread.sleep(60000);
  40.  
  41.                                 }
  42.  
  43.                                 catch (InterruptedException iE)
  44.  
  45.                                 {
  46.  
  47.                                        
  48.  
  49.                                 }
  50.  
  51.                         }
  52.  
  53.                 }
  54.  
  55.          
  56.  
  57.         @Override
  58.  
  59.         public IBinder getBinder()
  60.  
  61.         {
  62.  
  63.                 // TODO Auto-generated method stub
  64.  
  65.                 return null;
  66.  
  67.         }
  68.  
  69. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
Lex
Developer
Developer
 
Posts: 30
Joined: Fri Nov 16, 2007 11:03 pm

Postby plusminus » Fri Dec 28, 2007 2:14 pm

Hello Sachin,

the easiest would be to create a separate Thread, that sleep for 60.000 Milliseconds (== 1 Minute) then shows the notification and repeats until interrupted.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby dickwall » Thu Jan 03, 2008 1:11 am

Hi Sachin

While you could certainly use a thread in the way that plusminus suggests, there is a slightly easier and more efficient way of achieving the same thing in Android, using a Handler instead. If you would like to know more about this, please take a look at the "A Stitch in Time" blog entry over at http://android-developers.blogspot.com/ ... -time.html for more information about how to use a Handler instead of a separate thread.

Thanks

Dick
dickwall
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jan 02, 2008 11:32 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 11 guests