title: How to repeat an action every day in an Android app?
body: <p>I want to repeat an action every day; it must continue working even if the app is not running or the device has been restarted (rebooted).
  In my code I'm trying to show a TOAST message every 1 minute (as a test); it's working fine in the emulator but on a real device it doesn't work( i tried to do some changes to fixed as i see in some answers but still the same thing) </p>
  
  <p><strong>MyReceiver</strong> </p>
  
  <pre><code>class MyReceiver : BroadcastReceiver() {
      private val channelId = "com.medanis.hikamwahimam"
  
      override fun onReceive(context: Context, intent: Intent) {
          Log.i("TAG","/////////////////// SHOW NOTIFICATION NOW //////////////////////")
          val builder = NotificationCompat.Builder(context, channelId)
              .setSmallIcon(R.drawable.ic_stat_name)
              .setLargeIcon(BitmapFactory.decodeResource(context.resources,R.mipmap.ic_launcher_round))
              .setContentTitle("My notification")
              .setContentText("Much longer text that cannot fit one line...")
              .setStyle(
                  NotificationCompat.BigTextStyle()
                      .bigText("Much longer text that cannot fit one line...Much longer text that cannot fit one line..."))
              .setPriority(NotificationCompat.PRIORITY_DEFAULT)
          with(NotificationManagerCompat.from(context)) {
              notify(12345, builder.build()) }
          Toast.makeText(context,"This toast will be shown every X minutes", Toast.LENGTH_LONG).show()
      }
  }
  </code></pre>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>class MainActivity : AppCompatActivity() {
      private var mAlarmManager : AlarmManager? = null
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  //        showNotification()
  
          val mIntent = Intent(this, MyReceiver::class.java)
  
          val mPendingIntent = PendingIntent.getBroadcast(this, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT)
          mAlarmManager = this
              .getSystemService(Context.ALARM_SERVICE) as AlarmManager
          mAlarmManager!!.setRepeating(
              AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
              60000, mPendingIntent
          )
      }
  }
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;receiver android:name=".MyReceiver" &gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <blockquote>
    <p><strong>The Issues are :</strong></p>
    
    <p>1/- This code does not work with REAL DEVICE.</p>
    
    <p>2/- This code does not work if the user restart his device.</p>
  </blockquote>
  
  <p><em>A sample on <a href="https://github.com/Aniskonig/My-Periodic-App" rel="nofollow noreferrer">GitHub</a></em> (i had made some changes as my friend had suggested but still the same errors) </p>