title: How to fix Error: Unknown component while launching activity when pushing the app to a device?
body: <p>Sometimes (not all times) when I try to push (simply run) the code the from android-studio to my phone (Motorola 3G, though not phone specific), I am getting this error :-</p>
  
  <p>04/22 23:00:14: Launching app
  No local changes, not deploying APK</p>
  
  <pre><code>$ adb shell am start -n "com.xxxx.test/com.horntell.test.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
  Error while executing: am start -n "com.horntell.test/com.horntell.test.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
  Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.horntell.test/.MainActivity }
  usage: am [subcommand] [options]
  usage: am start [-D] [-W] [-P &lt;FILE&gt;] [--start-profiler &lt;FILE&gt;]
                 [--sampling INTERVAL] [-R COUNT] [-S] [--opengl-trace]
                 [--user &lt;USER_ID&gt; | current] &lt;INTENT&gt;
         am startservice [--user &lt;USER_ID&gt; | current] &lt;INTENT&gt;
         am stopservice [--user &lt;USER_ID&gt; | current] &lt;INTENT&gt;
         am force-stop [--user &lt;USER_ID&gt; | all | current] &lt;PACKAGE&gt;
         am kill [--user &lt;USER_ID&gt; | all | current] &lt;PACKAGE&gt;
         am kill-all
         am broadcast [--user &lt;USER_ID&gt; | all | current] &lt;INTENT&gt;
         am instrument [-r] [-e &lt;NAME&gt; &lt;VALUE&gt;] [-p &lt;FILE&gt;] [-w]
                 [--user &lt;USER_ID&gt; | current]
                 [--no-window-animation] [--abi &lt;ABI&gt;] &lt;COMPONENT&gt;
         am profile start [--user &lt;USER_ID&gt; current] [--sampling INTERVAL] &lt;PROCESS&gt; &lt;FILE&gt;
         am profile stop [--user &lt;USER_ID&gt; current] [&lt;PROCESS&gt;]
         am dumpheap [--user &lt;USER_ID&gt; current] [-n] &lt;PROCESS&gt; &lt;FILE&gt;
         am set-debug-app [-w] [--persistent] &lt;PACKAGE&gt;
         am clear-debug-app
         am set-watch-heap &lt;PROCESS&gt; &lt;MEM-LIMIT&gt;
         am clear-watch-heap
         am monitor [--gdb &lt;port&gt;]
         am hang [--allow-restart]
         am restart
         am idle-maintenance
         am screen-compat [on|off] &lt;PACKAGE&gt;
         am package-importance &lt;PACKAGE&gt;
         am to-uri [INTENT]
         am to-intent-uri [INTENT]
         am to-app-uri [INTENT]
         am switch-user &lt;USER_ID&gt;
         am start-user &lt;USER_ID&gt;
         am stop-user [-w] &lt;USER_ID&gt;
         am stack start &lt;DISPLAY_ID&gt; &lt;INTENT&gt;
         am stack movetask &lt;TASK_ID&gt; &lt;STACK_ID&gt; [true|false]
         am stack resize &lt;STACK_ID&gt; &lt;LEFT,TOP,RIGHT,BOTTOM&gt;
         am stack split &lt;STACK_ID&gt; &lt;v|h&gt; [INTENT]
         am stack list
         am stack info &lt;STACK_ID&gt;
         am task lock &lt;TASK_ID&gt;
         am task lock stop
         am task resizeable &lt;TASK_ID&gt; [true|false]
         am task resize &lt;TASK_ID&gt; &lt;LEFT,TOP,RIGHT,BOTTOM&gt;
         am get-config
         am set-inactive [--user &lt;USER_ID&gt;] &lt;PACKAGE&gt; true|false
         am get-inactive [--user &lt;USER_ID&gt;] &lt;PACKAGE&gt;
         am send-trim-memory [--user &lt;USER_ID&gt;] &lt;PROCESS&gt;
                 [HIDDEN|RUNNING_MODERATE|BACKGROUND|RUNNING_LOW|MODERATE|RUNNING_CRITICAL|COMPLETE]
  
  am start: start an Activity.  Options are:
      -D: enable debugging
      -W: wait for launch to complete
      --start-profiler &lt;FILE&gt;: start profiler and send results to &lt;FILE&gt;
      --sampling INTERVAL: use sample profiling with INTERVAL microseconds
          between samples (use with --start-profiler)
      -P &lt;FILE&gt;: like above, but profiling stops when app goes idle
      -R: repeat the activity launch &lt;COUNT&gt; times.  Prior to each repeat,
          the top activity will be finished.
      -S: force stop the target app before starting the activity
      --opengl-trace: enable tracing of OpenGL functions
      --user &lt;USER_ID&gt; | current: Specify which user to run as; if not
          specified then run as the current user.
  
  am startservice: start a Service.  Options are:
      --user &lt;USER_ID&gt; | current: Specify which user to run as; if not
          specified then run as the current user.
  
  am stopservice: stop a Service.  Options are:
      --user &lt;USER_ID&gt; | current: Specify which user to run as; if not
          specified then run as the current user.
  
  am force-stop: force stop everything associated with &lt;PACKAGE&gt;.
      --user &lt;USER_ID&gt; | all | current: Specify user to force stop;
          all users if not specified.
  
  am kill: Kill all processes associated with &lt;PACKAGE&gt;.  Only kills.
    processes that are safe to kill -- that is, will not impact the user
    experience.
      --user &lt;USER_ID&gt; | all | current: Specify user whose processes to kill;
          all users if not specified.
  
  am kill-all: Kill all background processes.
  
  am broadcast: send a broadcast Intent.  Options are:
      --user &lt;USER_ID&gt; | all | current: Specify which user to send to; if not
          specified then send to all users.
      --receiver-permission &lt;PERMISSION&gt;: Require receiver to hold permission.
  
  am instrument: start an Instrumentation.  Typically this target &lt;COMPONENT&gt;
    is the form &lt;TEST_PACKAGE&gt;/&lt;RUNNER_CLASS&gt;.  Options are:
      -r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT).  Use with
          [-e perf true] to generate raw output for performance measurements.
      -e &lt;NAME&gt; &lt;VALUE&gt;: set argument &lt;NAME&gt; to &lt;VALUE&gt;.  For test runners a
          common form is [-e &lt;testrunner_flag&gt; &lt;value&gt;[,&lt;value&gt;...]].
      -p &lt;FILE&gt;: write profiling data to &lt;FILE&gt;
      -w: wait for instrumentation to finish before returning.  Required for
          test runners.
      --user &lt;USER_ID&gt; | current: Specify user instrumentation runs in;
          current user if not specified.
      --no-window-animation: turn off window animations while running.
      --abi &lt;ABI&gt;: Launch the instrumented process with the selected ABI.
          This assumes that the process supports the selected ABI.
  
  am profile: start and stop profiler on a process.  The given &lt;PROCESS&gt; argument
    may be either a process name or pid.  Options are:
      --user &lt;USER_ID&gt; | current: When supplying a process name,
          specify user of process to profile; uses current user if not specified.
  
  am dumpheap: dump the heap of a process.  The given &lt;PROCESS&gt; argument may
    be either a process name or pid.  Options are:
      -n: dump native heap instead of managed heap
      --user &lt;USER_ID&gt; | current: When supplying a process name,
          specify user of process to dump; uses current user if not specified.
  
  am set-debug-app: set application &lt;PACKAGE&gt; to debug.  Options are:
      -w: wait for debugger when application starts
      --persistent: retain this value
  
  am clear-debug-app: clear the previously set-debug-app.
  
  am set-watch-heap: start monitoring pss size of &lt;PROCESS&gt;, if it is at or
      above &lt;HEAP-LIMIT&gt; then a heap dump is collected for the user to report
  
  am clear-watch-heap: clear the previously set-watch-heap.
  
  am bug-report: request bug report generation; will launch UI
      when done to select where it should be delivered.
  
  am monitor: start monitoring for crashes or ANRs.
      --gdb: start gdbserv on the given port at crash/ANR
  
  am hang: hang the system.
      --allow-restart: allow watchdog to perform normal system restart
  
  am restart: restart the user-space system.
  
  am idle-maintenance: perform idle maintenance now.
  
  am screen-compat: control screen compatibility mode of &lt;PACKAGE&gt;.
  
  am package-importance: print current importance of &lt;PACKAGE&gt;.
  
  am to-uri: print the given Intent specification as a URI.
  
  am to-intent-uri: print the given Intent specification as an intent: URI.
  
  am to-app-uri: print the given Intent specification as an android-app: URI.
  
  am switch-user: switch to put USER_ID in the foreground, starting
    execution of that user if it is currently stopped.
  
  am start-user: start USER_ID in background if it is currently stopped,
    use switch-user if you want to start the user in foreground.
  
  am stop-user: stop execution of USER_ID, not allowing it to run any
    code until a later explicit start or switch to it.
    -w: wait for stop-user to complete.
  
  am stack start: start a new activity on &lt;DISPLAY_ID&gt; using &lt;INTENT&gt;.
  
  am stack movetask: move &lt;TASK_ID&gt; from its current stack to the top (true) or   bottom (false) of &lt;STACK_ID&gt;.
  
  am stack resize: change &lt;STACK_ID&gt; size and position to &lt;LEFT,TOP,RIGHT,BOTTOM&gt;.
  
  am stack split: split &lt;STACK_ID&gt; into 2 stacks &lt;v&gt;ertically or &lt;h&gt;orizontally
     starting the new stack with [INTENT] if specified. If [INTENT] isn't
     specified and the current stack has more than one task, then the top task
     of the current task will be moved to the new stack. Command will also force
     all current tasks in both stacks to be resizeable.
  
  am stack list: list all of the activity stacks and their sizes.
  
  am stack info: display the information about activity stack &lt;STACK_ID&gt;.
  
  am task lock: bring &lt;TASK_ID&gt; to the front and don't allow other tasks to run.
  
  am task lock stop: end the current task lock.
  
  am task resizeable: change if &lt;TASK_ID&gt; is resizeable (true) or not (false).
  
  am task resize: makes sure &lt;TASK_ID&gt; is in a stack with the specified bounds.
     Forces the task to be resizeable and creates a stack if no existing stack
     has the specified bounds.
  
  am get-config: retrieve the configuration and any recent configurations
    of the device.
  
  am set-inactive: sets the inactive state of an app.
  
  am get-inactive: returns the inactive state of an app.
  
  am send-trim-memory: Send a memory trim event to a &lt;PROCESS&gt;.
  
  &lt;INTENT&gt; specifications include these flags and arguments:
      [-a &lt;ACTION&gt;] [-d &lt;DATA_URI&gt;] [-t &lt;MIME_TYPE&gt;]
      [-c &lt;CATEGORY&gt; [-c &lt;CATEGORY&gt;] ...]
      [-e|--es &lt;EXTRA_KEY&gt; &lt;EXTRA_STRING_VALUE&gt; ...]
      [--esn &lt;EXTRA_KEY&gt; ...]
      [--ez &lt;EXTRA_KEY&gt; &lt;EXTRA_BOOLEAN_VALUE&gt; ...]
      [--ei &lt;EXTRA_KEY&gt; &lt;EXTRA_INT_VALUE&gt; ...]
      [--el &lt;EXTRA_KEY&gt; &lt;EXTRA_LONG_VALUE&gt; ...]
      [--ef &lt;EXTRA_KEY&gt; &lt;EXTRA_FLOAT_VALUE&gt; ...]
      [--eu &lt;EXTRA_KEY&gt; &lt;EXTRA_URI_VALUE&gt; ...]
      [--ecn &lt;EXTRA_KEY&gt; &lt;EXTRA_COMPONENT_NAME_VALUE&gt;]
      [--eia &lt;EXTRA_KEY&gt; &lt;EXTRA_INT_VALUE&gt;[,&lt;EXTRA_INT_VALUE...]]
          (mutiple extras passed as Integer[])
      [--eial &lt;EXTRA_KEY&gt; &lt;EXTRA_INT_VALUE&gt;[,&lt;EXTRA_INT_VALUE...]]
          (mutiple extras passed as List&lt;Integer&gt;)
      [--ela &lt;EXTRA_KEY&gt; &lt;EXTRA_LONG_VALUE&gt;[,&lt;EXTRA_LONG_VALUE...]]
          (mutiple extras passed as Long[])
      [--elal &lt;EXTRA_KEY&gt; &lt;EXTRA_LONG_VALUE&gt;[,&lt;EXTRA_LONG_VALUE...]]
          (mutiple extras passed as List&lt;Long&gt;)
      [--efa &lt;EXTRA_KEY&gt; &lt;EXTRA_FLOAT_VALUE&gt;[,&lt;EXTRA_FLOAT_VALUE...]]
          (mutiple extras passed as Float[])
      [--efal &lt;EXTRA_KEY&gt; &lt;EXTRA_FLOAT_VALUE&gt;[,&lt;EXTRA_FLOAT_VALUE...]]
          (mutiple extras passed as List&lt;Float&gt;)
      [--esa &lt;EXTRA_KEY&gt; &lt;EXTRA_STRING_VALUE&gt;[,&lt;EXTRA_STRING_VALUE...]]
          (mutiple extras passed as String[]; to embed a comma into a string,
           escape it using "\,")
      [--esal &lt;EXTRA_KEY&gt; &lt;EXTRA_STRING_VALUE&gt;[,&lt;EXTRA_STRING_VALUE...]]
          (mutiple extras passed as List&lt;String&gt;; to embed a comma into a string,
           escape it using "\,")
      [--grant-read-uri-permission] [--grant-write-uri-permission]
      [--grant-persistable-uri-permission] [--grant-prefix-uri-permission]
      [--debug-log-resolution] [--exclude-stopped-packages]
      [--include-stopped-packages]
      [--activity-brought-to-front] [--activity-clear-top]
      [--activity-clear-when-task-reset] [--activity-exclude-from-recents]
      [--activity-launched-from-history] [--activity-multiple-task]
      [--activity-no-animation] [--activity-no-history]
      [--activity-no-user-action] [--activity-previous-is-top]
      [--activity-reorder-to-front] [--activity-reset-task-if-needed]
      [--activity-single-top] [--activity-clear-task]
      [--activity-task-on-home]
      [--receiver-registered-only] [--receiver-replace-pending]
      [--selector]
      [&lt;URI&gt; | &lt;PACKAGE&gt; | &lt;COMPONENT&gt;]
  
  
  Error: Unknown component: com.horntell.test/com.horntell.test.MainActivity
  
  Error while Launching activity
  </code></pre>
  
  <p>This problem occur mostly when I try to push the code for the first time. i.e. App is not already present in the phone.</p>
  
  <p>Sometimes, I have to restart the IDE, or phone or both to resolve this issue and it gets really frustrating sometimes.</p>