title: Start activity over lockscreen from notification intent
body: <p>How do I start an activity over the lock screen after clicking on a notification? Whatever I do it asks for my password and starts the activity after I unlock. It doesn't even get to the onCreate methods.</p>
  
  <pre><code>    &lt;activity
          android:name=".Locktask"
          android:configChanges="orientation"
          android:excludeFromRecents="true"
          android:noHistory="true"
          android:showOnLockScreen="true"
          android:showWhenLocked="true"
          android:taskAffinity=""
          android:exported="true"
          android:screenOrientation="portrait"
          android:launchMode="singleTask"
          android:theme="@style/AppTheme.NoActionBar" /&gt;
  
  
      Intent intent = new Intent(this, Locktask.class);
  
      PendingIntent pi = PendingIntent.getActivity(this, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      NotificationManager mNotificationManager =
              (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
      if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.O) {
          NotificationChannel channel = new NotificationChannel("locknote",
                  "locknote name",
                  NotificationManager.IMPORTANCE_HIGH);
          channel.setDescription("shows layout over lock.");
          channel.enableLights(true);
          channel.setLightColor(Color.RED);
          channel.enableVibration(true);
          channel.setShowBadge(false);
          channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
          channel.setVibrationPattern(new long[] { 0,0 });
          channel.enableVibration(false);
          if (mNotificationManager != null) {
              mNotificationManager.createNotificationChannel(channel);
          }
      }
      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "locknote")
  
              .setContentTitle("w")
              .setContentText("e")
              .setContentIntent(pi)
              .setSmallIcon(R.drawable.ic_action_lock_notification)
              .setPriority(NotificationCompat.PRIORITY_DEFAULT);
  
      NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
  
  
      notificationManager.notify(2, mBuilder.build());
  </code></pre>
  
  <p>Not a duplicate as that answer's permissions have already been added.</p>
  
  <p>Edit: SOVLED</p>
  
  <p>For any poor souls in the future, the notification has to have a custom layout with setCustomContentView() and a onclickpendingintent set to that view. The pending intent should point to an intent service, it's the only way intents can get handled from notifications while still locked.</p>