[android-developers] I want to stop alarm if set time passed

2011-09-15 Thread Chirag Raval
Hello,

I am developed one android application, in that application i want to show
notification to the user at every morning 9 am. For that i am creating a one
alarm class and called that alarm class's method from splash screen.So when
ever splash screen called my alarm class called.

Here i have one issue in my application . First time when i set time to
alarm it called my service but again after time passed it called my service
again . How can i stop it ? I used alarm manager's setRepeating method in
that i am set interval time is 24*60*60*1000.

Please Help me to sort out my problem.

My Alarm Class
-

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class Alarms
{
static void scheduleRegularSync(Context ctx)
{
scheduleSync(ctx);
}
 @SuppressWarnings("static-access")
private static void scheduleSync(Context ctx)
{
AlarmManager alarmManager =
(AlarmManager)ctx.getSystemService(ctx.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 14);
calendar.set(Calendar.MINUTE, 44);
calendar.set(Calendar.SECOND, 00);
PendingIntent pi = createPendingIntent(ctx);

long offset = calendar.get(Calendar.ZONE_OFFSET) +
calendar.get(Calendar.DST_OFFSET);
long sinceMidnight = (calendar.getTimeInMillis() + offset) % (24 * 60 *
60 * 1000);

Log.i("-- Time in Milli Seconds",""+sinceMidnight);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), 24*60*60*1000, pi);
Log.i("--- Alaram Called","--");
}
 private static PendingIntent createPendingIntent(Context context)
{
Intent myIntent = new Intent(context, MyAlarmService.class);
return PendingIntent.getService(context,(int) 0, myIntent, 0);
}
}

Thanks in Advance.

Regards,
Chirag Raval.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] I want to stop alarm if set time passed

2011-09-15 Thread Chirag Raval
Hello,

I am developed one android application, in that application i want to
show notification to the user at every morning 9 am. For that i am
creating a one alarm class and called that alarm class's method from
splash screen.So when ever splash screen called my alarm class called.

Here i have one issue in my application . First time when i set time
to alarm it called my service but again after time passed it called my
service again . How can i stop it ? I used alarm manager's
setRepeating method in that i am set interval time is 24*60*60*1000.

Please Help me to sort out my problem.

My Alarm Class
-

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class Alarms
{
static void scheduleRegularSync(Context ctx)
{
scheduleSync(ctx);
}

@SuppressWarnings("static-access")
private static void scheduleSync(Context ctx)
{
AlarmManager alarmManager =
(AlarmManager)ctx.getSystemService(ctx.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 14);
calendar.set(Calendar.MINUTE, 44);
calendar.set(Calendar.SECOND, 00);
PendingIntent pi = createPendingIntent(ctx);

long offset = calendar.get(Calendar.ZONE_OFFSET) +
calendar.get(Calendar.DST_OFFSET);
long sinceMidnight = (calendar.getTimeInMillis() + offset) % (24
* 60 * 60 * 1000);

Log.i("-- Time in Milli Seconds",""+sinceMidnight);

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), 24*60*60*1000, pi);
Log.i("--- Alaram Called","--");
}

private static PendingIntent createPendingIntent(Context context)
{
Intent myIntent = new Intent(context, MyAlarmService.class);
return PendingIntent.getService(context,(int) 0, myIntent, 0);
}
}

Thanks in Advance.

Regards,
Chirag Raval.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en