2

I have to make a different kind of notification in my application. The notifications should be shown even if the application is killed from the task manager. The notifications should be stacked one after the another. The existing notification code which I am using is given below.

This is the class for creating the notification:

public class TimeAlarm extends BroadcastReceiver {

     NotificationManager nm;

     @Override
     public void onReceive(Context context, Intent intent) {
      nm = (NotificationManager) context
        .getSystemService(Context.NOTIFICATION_SERVICE);
      CharSequence from = "Scheduled Training";
      CharSequence message = "Please attend the scheduled training";


      PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
        new Intent(), 0);
      Notification notif = new Notification(R.drawable.ic_launcher,
        "Scheduled Training", System.currentTimeMillis());
      notif.setLatestEventInfo(context, from, message, contentIntent);
      nm.notify(1, notif);
     }
    }

This is the code I am using in the activity to create the notifications:

  @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

  duration=(EditText)findViewById(R.id.duration_editText);
        dateAndTimeLabel=(TextView)findViewById(R.id.timeTxt);

        updateLabel();
        updateNotification();
        am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

     // On Click Confirm

            confirm=(ImageView)findViewById(R.id.confirm_imageView);
            confirm.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    getDateTime();
                     count++;
                   setOneTimeAlarm();
                }
            });

      }


     public void setOneTimeAlarm() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
             calendar.set(Calendar.MINUTE, minute);
             calendar.set(Calendar.SECOND, 0);





          Intent intent = new Intent(this, TimeAlarm.class);
          PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
            intent,count);
          am.set(AlarmManager.RTC_WAKEUP,
           calendar.getTimeInMillis(), pendingIntent);
         }


    void updateNotification()
          {
              hour= dateAndTime.get(Calendar.HOUR_OF_DAY);
              minute=dateAndTime.get(Calendar.MINUTE);
          }

This is not helping me achieve my goal. What should I do? I want to create kind of notification you can find in Ice Age village game.

4

0 回答 0