s или ДЕЙСТВИЯ отличаются, иначе они будут перезаписывать друг друга.

исал приложение для включения / выключения WiFi в запланированное время, выбранное ранее. Как это работает, очень просто: выберите время из таймера, а затем просто добавьте его. Программно он получает данные от таймера и устанавливает и тревогу. Сначала я записал код для своей деятельности и получателя вещания, ниже этого кода я напишу свои вопросы. Не волнуйтесь, я помещаю комментарии внутри кода, чтобы они были более понятными для чтения и понимания

Wifi.class:

public class WiFi extends AppCompatActivity {
private final int TEMP_REQUEST_CODE = 1;
private AlarmManager alarmManager;
private TimePicker timePicker;
private PendingIntent pendingIntent;
private Intent intent;
private Context context;
private Calendar calendar;
Intent alarmIntent;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wifi_class);
    timePicker = (TimePicker) findViewById(R.id.timePicker1);
    timePicker.setIs24HourView(true);
    setTitle("Set WiFi off/on");
    //store context in global variable
    context = getApplicationContext();
    //creates an intent that will be used in pending intent
    initializeView();
    //creates pending intent
    createAlarmIntent();
    //checks if alarm exists and sets matching text on the screen
    checkAlarmExists();

}

// I got an add button in my toolbar that saves the alarm, same as to delete 
an alarm
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.tick:
            Alarm();
            finish();
            return true;
        case R.id.dismiss:
            cancelAlarm();
        default:
            return super.onOptionsItemSelected(item);
    }
}
//this method initialize intent and stores it into variable, 
WiFiService.class extends BroadcastReceiver
//and all what it has to do is to turn wifi on/off
private void initializeView () {
    intent = new Intent(context, WifiService.class);

    //creating global pendingIntent variable
     pendingIntent = PendingIntent.getBroadcast(context,
            0,
            intent,
            0);
    //creating global alarmManager variable
     alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
}
//this method gets selected time from timepicker and calls another method to 
create an alarm
private void Alarm() {
     calendar = Calendar.getInstance();
    if (Build.VERSION.SDK_INT >= 23) {
        calendar.set(
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH),
                timePicker.getHour(),
                timePicker.getMinute(), 0
        );

    } else {
        calendar.set(
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH),
                timePicker.getCurrentHour(),
                timePicker.getCurrentMinute(),
                0);
    }
    setAlarm();
}

/**
 * This method sets Alarm that will be executed even in Doze mode and will 
intent WifiServices class,
 * in the result it will turn wifi off or on
 *
 */
private PendingIntent createAlarmIntent() {
     alarmIntent = new Intent(this, WifiService.class);
    return PendingIntent.getBroadcast(this, TEMP_REQUEST_CODE,
            alarmIntent, 0);
}
private void setAlarm() {
//setting alarm
    PendingIntent intent = createAlarmIntent();
    if (Build.VERSION.SDK_INT >= 23) {
        alarmManager.setAlarmClock(new 
AlarmManager.AlarmClockInfo(calendar.getTimeInMillis(), pendingIntent), 
intent);
}
    else {
        alarmManager.setExact(AlarmManager.RTC, calendar.getTimeInMillis(), 
pendingIntent);
    }

    long AlarmMgs = calendar.getTimeInMillis() - 
Calendar.getInstance().getTimeInMillis();
    Toast.makeText(context, "Alarm will be executed in " + AlarmMgs / 1000 / 
60 + "min", Toast.LENGTH_SHORT).show();

}


/**
 * This method should cancel alarm that is being currently set. There is no 
 if/else statement 
 * because it always says that alarm exists (see next method)
 */
private void cancelAlarm() {

    alarmManager.cancel(createAlarmIntent());
    Toast.makeText(context, "Alarm dismissed", Toast.LENGTH_SHORT).show();
    checkAlarmExists();
}

/**
 * This method checks wrether alarm is set or not and assigns that into 
 TextView
 * Unfortunately it always says it exists
 */
private void checkAlarmExists() {

    boolean alarmExists =
            (PendingIntent.getBroadcast(context,
                    0,
                    intent,
                    PendingIntent.FLAG_NO_CREATE)
                    != null);

    TextView alarmSetter = (TextView) findViewById(R.id.alarmSet);
    if (alarmExists) {
        alarmSetter.setText("Alarm is set");

    } else {
        alarmSetter.setText("Alarm is not set yet");
    }
}
    //TODO: (1): Create more than 1 alarm without replacing one before
    //TODO: (2): Cancel one of them, not all of them
    //TODO: (3): Edit those alarms 
}

Класс WifiService:

public class WifiService extends BroadcastReceiver {

public static final String TAG = "WiFi";

@Override
public void onReceive(Context context, Intent intent) {
//        if 
(intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) 
{

        WifiManager wifiManager = (WifiManager) 
context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        Log.v("Wifi", "checked");
        if (wifiManager.isWifiEnabled()) {
            wifiManager.setWifiEnabled(false);
            Toast.makeText(context, "Turning wifi off", 
Toast.LENGTH_SHORT).show();
            Log.v(TAG, "Turned off");
        } else {
            wifiManager.setWifiEnabled(true);
            Toast.makeText(context, "turning wifi on", 
Toast.LENGTH_SHORT).show();
            Log.v(TAG, "turned off");
        }
//        }
    Log.v(TAG, "Works");
}

}

Хорошо, я оставил 3 кода TODO в коде: 1. Я хочу создать 1 или более сигналов тревоги без замены существующего, все, что мне нужно сделать, это установить флаг ожидания для обновления каждый раз, когда я устанавливаю сигнал тревоги? 2. Если я создаю, например, 3 тревоги, я хочу отменить одну из них, указанную. В любом случае, я буду хранить эти сигналы в базе данных, поэтому мой способ мышления заключается в следующем: создать сигнал -> добавить его в базу данных -> отобразить в списке -> если удалить -> удалить из списка -> деактивировать 3. Редактирование будильников. Я знаю, как редактировать элементы в базе данных, но как редактировать запланированный будильник? Я имею в виду, чтобы изменить его время огня. Это все о воссоздании будильника?

Кто-нибудь может ответить на мои вопросы? Заранее спасибо.

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

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