The code below automatically fires notification on onCreate of MainActivity. I want to fire it only at set time which is at 17:10:00 <p><strong>This is MainActivity.class</strong></p> <pre><code>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.Handler; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class MainActivity extends Activity { private TextView textView1,textView2, textView3, textView4; Intent intent1,intent2; private PendingIntent pendingIntent; ImageView imageView; boolean doubleBackToExitPressedOnce = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String valid_until = "26/02/2016"; SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date strdate = null; try{ strdate = sdf.parse(valid_until); } catch (ParseException e){ e.printStackTrace(); } if(new Date().after(strdate)){ MainActivity.this.finish(); Toast.makeText(MainActivity.this,"Time expired",Toast.LENGTH_LONG).show(); } //program for alarm manager Intent alarmIntent = new Intent(MainActivity.this,AlarmReciever.class); pendingIntent = PendingIntent.getBroadcast(MainActivity.this,0,alarmIntent,0); alarmStart(); } public void alarmStart(){ AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(calendar.HOUR_OF_DAY, 17); calendar.set(calendar.MINUTE,10 ); calendar.set(calendar.SECOND, 00); // pendingIntent = PendingIntent.getService(context,0,new Intent(context, AlarmReciever.class),PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); } @Override public void onBackPressed() { if (doubleBackToExitPressedOnce) { super.onBackPressed(); MainActivity.this.finish(); return; } this.doubleBackToExitPressedOnce = true; Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show(); new Handler().postDelayed(new Runnable() { @Override public void run() { doubleBackToExitPressedOnce = false; } }, 2000); } } </code></pre> <p><strong>This is the AlarmReciever.class</strong></p> <pre><code>import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.support.v4.app.NotificationCompat; import android.widget.Toast; import java.util.Date; public class AlarmReciever extends BroadcastReceiver { private DBManager dbManager; NotificationCompat.Builder notification; private static final int UNIQUEID=1; int i=0; public AlarmReciever() { } @Override public void onReceive(Context context, Intent intent) { // TODO: This method is called when the BroadcastReceiver is receiving // an Intent broadcast. Toast.makeText(context, "Alarm worked", Toast.LENGTH_LONG).show(); notification = new NotificationCompat.Builder(context); i++; notification.setAutoCancel(true); notification.setSmallIcon(R.drawable.notifylogo); notification.setTicker("Payment Status"); notification.setWhen(System.currentTimeMillis()); notification.setContentTitle("Zion Fitness Club"); notification.setContentText(i + " notifications recieved"); Intent intent1 = new Intent(context,Payment_list.class); PendingIntent pendingIntent = PendingIntent.getActivity(context,0, intent1, PendingIntent.FLAG_UPDATE_CURRENT); notification.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(UNIQUEID,notification.build()); } </code></pre> <p>The notification has to be fired only at the set time. But the problem is that it is also being fired at onCreate of the MainActivity.class.... Please help to solve this problem. </p>