C: SIGALRM – alarm to display message every second

Signal handlers are not supposed to contain “business logic” or make library calls such as printf. See C11 ยง7.1.4/4 and its footnote: Thus, a signal handler cannot, in general, call standard library functions. All the signal handler should do is set a flag to be acted upon by non-interrupt code, and unblock a waiting system … Read more

Android AlarmManager problem with setting & resetting an alarm

When canceling the AlarmManager do not use a PendingIntent with a flag of FLAG_CANCEL_CURRENT. Instead, cancel the PendingIntent explicitly after canceling the alarm: am = (AlarmManager) getSystemService(getApplicationContext().ALARM_SERVICE); Intent i = new Intent(getApplicationContext(),AlarmReceiver.class); PendingIntent p = PendingIntent.getBroadcast(getApplicationContext(), 0, i, 0); am.cancel(p); p.cancel();

signal.alarm replacement in Windows [Python]

The most robust solution is to use a subprocess, then kill that subprocess. Python2.6 adds .kill() to subprocess.Popen(). I don’t think your threading approach works as you expect. Deleting your reference to the Thread object won’t kill the thread. Instead, you’d need to set an attribute that the thread checks once it wakes up.

How to repeat notification daily on specific time in android through background service

First set the Alarm Manager as below Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 18); calendar.set(Calendar.MINUTE, 30); calendar.set(Calendar.SECOND, 0); Intent intent1 = new Intent(MainActivity.this, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0,intent1, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) MainActivity.this.getSystemService(MainActivity.this.ALARM_SERVICE); am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); Create an Broadcast Receiver Class “AlarmReceiver” in this raise the notifications when onReceive public class AlarmReceiver extends … Read more

Android – how to set an alarm to a specific date

package your.pack.name; import java.util.Calendar; import android.app.Activity; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; public class AlarmActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); cal.clear(); cal.set(2012,2,8,18,16); AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, … Read more

Start app at a specific time

You can do it with AlarmManager, heres a short example. First you need to set the alarm: AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE); Date futureDate = new Date(new Date().getTime() + 86400000); futureDate.setHours(8); futureDate.setMinutes(0); futureDate.setSeconds(0); Intent intent = new Intent(con, MyAppReciever.class); PendingIntent sender = PendingIntent.getBroadcast(con, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); am.set(AlarmManager.RTC_WAKEUP, futureDate.getTimeInMillis(), sender); Next, You need to create a … Read more

How to automatically restart a service even if user force close it?

First of all, it is really very bad pattern to run service forcefully against the user’s willingness. Anyways, you can restart it by using a BroadcastReceiver which handles the broadcast sent from onDestroy() of your service. StickyService.java public class StickyService extends Service { private static final String TAG = “StickyService”; @Override public IBinder onBind(Intent arg0) … Read more

Android Alarm Clock UI

The stock alarm clock app is open source, so check it out by yourself. Preference Layout see here: <?xml version=”1.0″ encoding=”utf-8″?> <PreferenceScreen xmlns:android=”http://schemas.android.com/apk/res/android” android:title=”@string/set_alarm”> <CheckBoxPreference android:key=”on” android:title=”@string/enable”/> <Preference android:key=”time” android:title=”@string/time”/> <com.android.alarmclock.AlarmPreference android:key=”alarm” android:title=”@string/alert” android:ringtoneType=”alarm” android:showDefault=”false” android:showSilent=”false” /> <CheckBoxPreference android:key=”vibrate” android:title=”@string/alarm_vibrate”/> <com.android.alarmclock.RepeatPreference android:key=”setRepeat” android:title=”@string/alarm_repeat” /> <EditTextPreference android:key=”label” android:title=”@string/label” android:dialogTitle=”@string/label” /> </PreferenceScreen> Preference activity see here, note … Read more

Delete alarm from AlarmManager using cancel() – Android

Try this flag: PendingIntent.FLAG_UPDATE_CURRENT Instead of: PendingIntent.FLAG_CANCEL_CURRENT So the PendingIntent will look like this: PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, alert.idAlert, intent, PendingIntent.FLAG_UPDATE_CURRENT) (Make sure that you use same alert object and mContext!) A side note: If you want one global AlarmManager, put the AlarmManager in a static variable (and initialize it only if it’s null).