title: Is it possible to run java code when activity is not launched?
body: <p>I am working on an alarm java application.
  I want to run <code>Alarm();</code> function when the systems clock arrives to the <code>targetTime</code>.
  But I want to do these even the application is not open.
  So somehow I want to run it in androids background.</p>
  <p>My code :</p>
  <pre><code>void AlarmCheck (DateTimeAlarm currentTime, DateTimeAlarm targetTime)
  {
      if(!targetTime.alarmed &amp;&amp; currentTime.day == targetTime &amp;&amp;
          currentTime.hour == targetTime.hour &amp;&amp; currentTime.minute &gt;= targetTime.minute)
      {
          targetTime.alarmed = true;
          Alarm();
      }
  }
  </code></pre>
  <p>And this is the class for the <code>DateTimeAlarm</code> :</p>
  <pre><code>public class DateTimeAlarm
  {
      public int day;
      public int hour;
      public int minute;
      public bool alarmed = false;
  
      public DateTimeAlarm(int day, int hour, int minute)
      {
          this.day = day;
          this.hour = hour;
          this.minute= minute;
      }
  }
  </code></pre>
  <p>I have no idea where to put this code PLEASE HELP ME.</p>
  <p>I am new to java so please explain easily. thank you for any suggesions.</p>