title: How to launch an activity from a lockscreen widget, without unlocking?
body: <p>I have a button on a lockscreen widget, and I'd like the button to launch an activity when pressed.  If the screen is locked, I want the activity to appear over the lockscreen, without the user having to enter the PIN or pattern or whatever, and the lockscreen should reappear when the user leaves the activity.</p>
  
  <p>I know about <code>WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED</code>, and my activity <em>does</em> appear over the lockscreen if I launch it manually using <code>am start</code> from an ADB shell.  The problem is, when I press the button in the widget, it makes me enter the unlock PIN before it creates the activity at all.</p>
  
  <p>I have this code in my widget provider:</p>
  
  <pre><code>@Override
  public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
      for (final int appWidgetId : appWidgetIds) {
          // Get the RemoteViews for controlling this widget instance.
          final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget);
  
          // Construct an intent to launch the activity.
          final Intent intent = new Intent(context, MyActivity.class);
          intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  
          // Attach the intent to the widget's button.
          final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
          views.setOnClickPendingIntent(R.id.my_button, pendingIntent);
  
          appWidgetManager.updateAppWidget(appWidgetId, views);
      }
  }
  </code></pre>
  
  <p>And here's the code in <code>MyActivity</code>:</p>
  
  <pre><code>public MyActivity() {
      Log.d(TAG, "Activity instantiated");
  }
  
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      // Allow this activity to appear over the lock screen.
      final Window window = getWindow();
      window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
  
      setContentView(R.layout.my_activity);
  }
  </code></pre>
  
  <p>When I press the button in the widget, I'm prompted for the unlock PIN.  The log message in the activity's constructor doesn't appear until <em>after</em> I enter the PIN, which means that Android is deciding to ask for the pin <em>before</em> the <code>FLAG_SHOW_WHEN_LOCKED</code> can have any effect.</p>
  
  <p>Is there a way to tell Android that I want to launch the activity while the screen is still locked?  Maybe a flag that I can set on my <code>Intent</code> or <code>PendingIntent</code>?</p>