关于Android Reminder Snoozing的问题

时间:2013-03-26 11:22:41

标签: android reminders snoop

我创建了一个带有Snoozing选项的Reminder应用程序..当只有一个提醒激活暂停时,一切都没问题。当我添加第二个提醒时,第一个被第二个提醒复制(覆盖)...我这里的代码。 Plz帮帮我..

reminButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            contentTitle = nameEdit.getText().toString();
            contentText = descEdit.getText().toString();
            contentSnooze = snoozeEdit.getText().toString();

            ContentValues details = new ContentValues();
            details.put("Name", contentTitle);
            details.put("Description", contentText);
            details.put("SnoozeTime", contentSnooze);

            db.insert("snoozetable", null, details);

            Toast.makeText(getApplication(), "Successfully Saved", Toast.LENGTH_LONG).show();

            if (dateFlag == true && timeFlag == true) {
                notificationCount = notificationCount + 1;
                dateFlag = false;
                timeFlag = false;
                time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
                        + "-" + mMinute;
                SimpleDateFormat df = new SimpleDateFormat(
                        "yyyy-MM-dd hh-mm");
                Date dt = null;
                try {
                    dt = df.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (java.text.ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                long when = dt.getTime();
                /*contentTitle = nameEdit.getText().toString();
                contentText = descEdit.getText().toString();*/
                AlarmManager mgr = (AlarmManager) mContext
                        .getSystemService(Context.ALARM_SERVICE);
                Intent notificationIntent = new Intent(mContext,
                        ReminderAlarm.class);
                notificationIntent.putExtra("Name", contentTitle);
                notificationIntent.putExtra("Description", contentText);
                notificationIntent.putExtra("NotifyCount",
                        notificationCount);
                PendingIntent pi = PendingIntent.getBroadcast(mContext,
                        notificationCount, notificationIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
                Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
                        Toast.LENGTH_LONG).show();
                contentTitle = "";
                contentText = "";
                descEdit.setText("");
                snoozeEdit.setText("");

            }

reminButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            contentTitle = nameEdit.getText().toString();
            contentText = descEdit.getText().toString();
            contentSnooze = snoozeEdit.getText().toString();

            ContentValues details = new ContentValues();
            details.put("Name", contentTitle);
            details.put("Description", contentText);
            details.put("SnoozeTime", contentSnooze);

            db.insert("snoozetable", null, details);

            Toast.makeText(getApplication(), "Successfully Saved", Toast.LENGTH_LONG).show();

            if (dateFlag == true && timeFlag == true) {
                notificationCount = notificationCount + 1;
                dateFlag = false;
                timeFlag = false;
                time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
                        + "-" + mMinute;
                SimpleDateFormat df = new SimpleDateFormat(
                        "yyyy-MM-dd hh-mm");
                Date dt = null;
                try {
                    dt = df.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (java.text.ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                long when = dt.getTime();
                /*contentTitle = nameEdit.getText().toString();
                contentText = descEdit.getText().toString();*/
                AlarmManager mgr = (AlarmManager) mContext
                        .getSystemService(Context.ALARM_SERVICE);
                Intent notificationIntent = new Intent(mContext,
                        ReminderAlarm.class);
                notificationIntent.putExtra("Name", contentTitle);
                notificationIntent.putExtra("Description", contentText);
                notificationIntent.putExtra("NotifyCount",
                        notificationCount);
                PendingIntent pi = PendingIntent.getBroadcast(mContext,
                        notificationCount, notificationIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
                Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
                        Toast.LENGTH_LONG).show();
                contentTitle = "";
                contentText = "";
                descEdit.setText("");
                snoozeEdit.setText("");

            }
reminButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            contentTitle = nameEdit.getText().toString();
            contentText = descEdit.getText().toString();
            contentSnooze = snoozeEdit.getText().toString();

            ContentValues details = new ContentValues();
            details.put("Name", contentTitle);
            details.put("Description", contentText);
            details.put("SnoozeTime", contentSnooze);

            db.insert("snoozetable", null, details);

            Toast.makeText(getApplication(), "Successfully Saved", Toast.LENGTH_LONG).show();

            if (dateFlag == true && timeFlag == true) {
                notificationCount = notificationCount + 1;
                dateFlag = false;
                timeFlag = false;
                time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
                        + "-" + mMinute;
                SimpleDateFormat df = new SimpleDateFormat(
                        "yyyy-MM-dd hh-mm");
                Date dt = null;
                try {
                    dt = df.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (java.text.ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                long when = dt.getTime();
                /*contentTitle = nameEdit.getText().toString();
                contentText = descEdit.getText().toString();*/
                AlarmManager mgr = (AlarmManager) mContext
                        .getSystemService(Context.ALARM_SERVICE);
                Intent notificationIntent = new Intent(mContext,
                        ReminderAlarm.class);
                notificationIntent.putExtra("Name", contentTitle);
                notificationIntent.putExtra("Description", contentText);
                notificationIntent.putExtra("NotifyCount",
                        notificationCount);
                PendingIntent pi = PendingIntent.getBroadcast(mContext,
                        notificationCount, notificationIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
                Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
                        Toast.LENGTH_LONG).show();
                contentTitle = "";
                contentText = "";
                descEdit.setText("");
                snoozeEdit.setText("");

            }

reminButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            contentTitle = nameEdit.getText().toString();
            contentText = descEdit.getText().toString();
            contentSnooze = snoozeEdit.getText().toString();

            ContentValues details = new ContentValues();
            details.put("Name", contentTitle);
            details.put("Description", contentText);
            details.put("SnoozeTime", contentSnooze);

            db.insert("snoozetable", null, details);

            Toast.makeText(getApplication(), "Successfully Saved", Toast.LENGTH_LONG).show();

            if (dateFlag == true && timeFlag == true) {
                notificationCount = notificationCount + 1;
                dateFlag = false;
                timeFlag = false;
                time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
                        + "-" + mMinute;
                SimpleDateFormat df = new SimpleDateFormat(
                        "yyyy-MM-dd hh-mm");
                Date dt = null;
                try {
                    dt = df.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (java.text.ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                long when = dt.getTime();
                /*contentTitle = nameEdit.getText().toString();
                contentText = descEdit.getText().toString();*/
                AlarmManager mgr = (AlarmManager) mContext
                        .getSystemService(Context.ALARM_SERVICE);
                Intent notificationIntent = new Intent(mContext,
                        ReminderAlarm.class);
                notificationIntent.putExtra("Name", contentTitle);
                notificationIntent.putExtra("Description", contentText);
                notificationIntent.putExtra("NotifyCount",
                        notificationCount);
                PendingIntent pi = PendingIntent.getBroadcast(mContext,
                        notificationCount, notificationIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
                Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
                        Toast.LENGTH_LONG).show();
                contentTitle = "";
                contentText = "";
                descEdit.setText("");
                snoozeEdit.setText("");

            }

ReminderActivity.java

reminButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            contentTitle = nameEdit.getText().toString();
            contentText = descEdit.getText().toString();
            contentSnooze = snoozeEdit.getText().toString();


                time = mYear + "-" + mMonth + "-" + mDay + " " + mHour
                        + "-" + mMinute;
                SimpleDateFormat df = new SimpleDateFormat(
                        "yyyy-MM-dd hh-mm");
                Date dt = null;
                try {
                    dt = df.parse(time);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (java.text.ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                long when = dt.getTime();

                AlarmManager mgr = (AlarmManager) mContext
                        .getSystemService(Context.ALARM_SERVICE);
                Intent notificationIntent = new Intent(mContext,
                        ReminderAlarm.class);
                notificationIntent.putExtra("Name", contentTitle);
                notificationIntent.putExtra("Description", contentText);
                notificationIntent.putExtra("NotifyCount",
                        notificationCount);
                PendingIntent pi = PendingIntent.getBroadcast(mContext,
                        notificationCount, notificationIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
                Toast.makeText(mContext, contentTitle +" Reminder Activated" + notificationCount,
                        Toast.LENGTH_LONG).show();




        }

ReminderAlarm.java

public void onReceive(Context context, Intent intent) {

    mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence name = intent.getStringExtra("Name");
    CharSequence desc = intent.getStringExtra("Description");
    notificationCount = Integer.parseInt(intent.getExtras().get("NotifyCount")
            .toString());

    sound = new Sound(context);
    sound.play();

    Intent notifyIntent = new Intent(context, ReminderPopup.class);
    notifyIntent.putExtra("Name", name);
    notifyIntent.putExtra("Description", desc);
    notifyIntent.putExtra("NotifyCount", notificationCount);
    PendingIntent contentIntent = PendingIntent.getActivity(context, notificationCount,
            notifyIntent, 0);

    notification = new Notification(R.drawable.ic_launcher, "Notification",
            System.currentTimeMillis());
    notification.setLatestEventInfo(context, name, desc, contentIntent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    mNotificationManager.notify(
            Integer.parseInt(intent.getExtras().get("NotifyCount")
                    .toString()), notification);

ReminderPopup.java

public void onClick(DialogInterface dialog, int which) {
            if (minute != 0) {



                cal = Calendar.getInstance();
                mYear = cal.get(Calendar.YEAR);
                mMonth = cal.get(Calendar.MONTH) + 1;
                mDay = cal.get(Calendar.DATE);
                mHour = cal.get(Calendar.HOUR_OF_DAY);
                mMinute = cal.get(Calendar.MINUTE);
                snooze = mYear + "-" + mMonth + "-" + mDay + " " + mHour
                        + "-" + (mMinute + minute);
                SimpleDateFormat df = new SimpleDateFormat(
                        "yyyy-MM-dd hh-mm");
                Date dt = null;
                try {
                    dt = df.parse(snooze);
                } catch (ParseException e) {
                    e.printStackTrace();
                } catch (java.text.ParseException e) {
                    e.printStackTrace();
                }
                when = dt.getTime();

                AlarmManager mgr = (AlarmManager) getApplicationContext()
                        .getSystemService(Context.ALARM_SERVICE);
                Intent notificationIntent = new Intent(
                        getApplicationContext(), ReminderAlarm.class);
                notificationIntent.putExtra("Name", name);

                notificationIntent.putExtra("Description", desc);

                notificationIntent.putExtra("NotifyCount",
                        notificationCount);
                PendingIntent pi = PendingIntent.getBroadcast(
                        getApplicationContext(), notificationCount,
                        notificationIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mgr.set(AlarmManager.RTC_WAKEUP, when, pi);
                Toast.makeText(getApplicationContext(),
                        name +" Reminder Snoozed for " + minute + " Minutes " + notificationCount,
                        Toast.LENGTH_LONG).show();
            }

1 个答案:

答案 0 :(得分:0)

我找到了这个问题的答案..我使用" android:theme =" @ style / Theme_Dialog_Translucent">"将ReminderPopup活动设置为透明活动。当我设置暂停时,只有AlertDialog会让ReminderPopup(透明)活动失望。因此,当我设置下一次暂停时,它将更新现有的。在AlertDialog结尾处为Positive和Negative按钮添加finish()..