title: Android: App not started by AlarmManager after app exit
body: <p>I'm trying to make an app to restart from a command sent by my server, searching on the internet i find that the best way to do this is by using <code>AlarmManager</code> so it starts the app at some moment.</p>
  <p>So the code i've made this far looks like this:</p>
  <pre><code>val intent = Intent(this, StartActivity::class.java)
  val wait = TimeUnit.SECONDS.toMillis(3)
  val intentId = 123
  
  intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
  intent.putExtra(EXTRA_RESTART_ID, this.restartId)
  intent.putExtra(EXTRA_COMMAND_NAME, this.restartCommandName)
  
  val pendingIntent = PendingIntent.getActivity(this.applicationContext, intentId, intent, PendingIntent.FLAG_ONE_SHOT)
  val manager: AlarmManager = this.getSystemService(Context.ALARM_SERVICE) as AlarmManager
  
  // Set alarm manager to start after 3s
  manager.set(AlarmManager.RTC, System.currentTimeMillis() + wait, pendingIntent)
  
  // Kill application
  this.finish()
  exitProcess(2)
  </code></pre>
  <p>Doing this i've noticed that the app doesn't start again consistently.. sometimes it doesn't work and i have no idea why it doesn't, i have tried changing the wait time, as well as the intent id and exit code, but it just continues to be inconsistent.</p>
  <p>Also.. checking the alarm system in shell using <code>adb shell dumpsys alarm</code> doesn't show the alarm added by the application.</p>
  <p>What could be the cause of the app not starting again sometimes?</p>
  <p><strong>Note:</strong> Phone is running on Android 9</p>