Как остановить AlarmManager при запуске активности

Я новичок в Android. Сегодня я попытался поработать с AlarmManage для моего приложения Reminder, которое позволяет пользователям вводить часы и минуты для отображения уведомления, и у меня возникли некоторые проблемы с ним. 1. Первая проблема - когда появляется уведомление, оно просто вибрирует и не имеет звука, хотя я установил звук по умолчанию для уведомлений и настройку разрешения звука для своего телефона. 2. когда я закрываю приложение, если я касаюсь уведомления, отображается MainActivity и AlarmManager снова работает, что заставляет мое приложение снова отображать уведомление. Но если я коснусь уведомления при открытии приложения, уведомление не будет отображаться. поэтому я хочу, чтобы моя заявка была раз только уведомлена Как я могу это сделать? 3. Хотя я установил время для напоминания, но когда я закрывал приложение, иногда на моем телефоне появлялось уведомление о моем приложении для напоминания в то время, которое я никогда не устанавливал. Как я могу решить эту проблему?

MyAlarmService

private NotificationManager mManager;

@Override
public IBinder onBind(Intent arg0)
{
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate()
{
    // TODO Auto-generated method stub
    super.onCreate();
}

@SuppressWarnings("static-access")
@Override
public void onStart(Intent intent, int startId)
{
    super.onStart(intent, startId);
   // Toast.makeText(this, "I'm running", Toast.LENGTH_SHORT).show();
    long[] v = {500,1000};
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setVibrate(v)
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setSmallIcon(R.drawable.ic_remind)
                    .setContentTitle("My notification")
        .setContentText("This is a test message!");
    mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    mBuilder.setAutoCancel(true);
    Intent intent1 = new Intent(this.getApplicationContext(),MainActivity.class);
    intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent1);



    PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(),0, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(pendingNotificationIntent);
    mManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    mManager.notify(0, mBuilder.build());

}

@Override
public void onDestroy()
{
    // TODO Auto-generated method stub
    super.onDestroy();
}

Получатель

public void onReceive(Context context, Intent intent)
{
    Intent service1 = new Intent(context, MyAlarmService.class);
    context.startService(service1);
}

Основная деятельность

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final EditText edt_hours = (EditText)findViewById(R.id.edt_hour);
    final EditText edt_minutes = (EditText)findViewById(R.id.edt_minutes);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(edt_hours.getText().toString()));
             calendar.set(Calendar.MINUTE, Integer.parseInt(edt_minutes.getText().toString()));
            //calendar.set(Calendar.SECOND,0);

            Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
            pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent,0);

            alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
            alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

        }
    });



} //end onCre

p / s: мне очень жаль, если мой вопрос не ясен, потому что мой английский не очень хорош. И я хочу сказать спасибо за всех, кто прочитал этот вопрос.

Ответы на вопрос(1)

Ваш ответ на вопрос