title: Dynamic Shortcuts to open Fragments in Android
body: <p>Hi I'm developing an application that has 2 types of user: Admin and normal user; The admin obviously has more actions than the normal user, so I need to use dynamic Shortcuts, depending on the user the Shortcuts are created.</p>
  
  <p>At this point everything is already codified and working. However, at the time of assigning an <code>Intent</code>, even to the <code>MainActivity</code> I receive an error. </p>
  
  <pre><code>Intent intent = new Intent();
  intent.setComponent(new ComponentName("com.motusk.Monit", "com.motusk.Monit.activity.MainActivity"));
  
  shortcut.add(new ShortcutInfo.Builder(this, "ub")
     .setShortLabel("Location")
     .setLongLabel("Location")
     .setIcon(Icon.createWithResource(this, R.drawable.bg))
     .setIntent(intent)
     .build());
  </code></pre>
  
  <p>I also tried with:</p>
  
  <pre><code>Intent intent = new Intent(this, MainActivity.class);
  </code></pre>
  
  <p>But, in both I get the error:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.motusk.Monit/com.motusk.Monit.activity.MainActivity}: java.lang.NullPointerException: intent's action must be set</p>
  </blockquote>
  
  <p>In what I need help with is:</p>
  
  <p>1) How to create a correct <code>Intent</code> to the <code>MainActivity</code>?</p>
  
  <p>2) How to know which shortcut was pressed? (The process of depending on which shortcut was pressed to open a certain <code>Fragment</code> will be performed in the <code>MainActivity</code>, that's why I need to know which Shortcut was pressed).</p>