-1

我已经创建了一个带有打盹选项的提醒应用程序.. 当只为一个提醒激活打盹时一切都很好.. 当我添加第二个提醒时,第一个被第二个重复(覆盖).. 我在这里附加了代码. 请帮帮我..

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("");

            }

提醒活动.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();




        }

提醒警报.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();
            }

4

1 回答 1

0

我找到了这个问题的答案。我使用“android:theme="@style/Theme_Dialog_Translucent">”将 ReminderPopup Activity 设置为透明活动。当我设置打盹时,只有 AlertDialog 会消失,而不是 ReminderPopup(透明)活动。所以当我设置下一个打盹时,它会更新现有的。在 AlertDialog 的末尾为 Positive 和 Negative 按钮添加 finish() ..

于 2013-03-27T09:30:05.037 回答