How to correctly use the Android command line Startup Program

Source: Internet
Author: User

There are many ways to start Android applications. You can start them using the Quick Start method we introduced earlier, in addition, you can use the Android command line to start the program. In Android, in addition to starting a program from the interface, you can also start the program from the command line, using the command line tool am.

The Android Command Line Method for starting a program is

 
 
  1. # Am start-n {package name}/{package name}. {activity name}

The startup method can be obtained from the AndroidManifest. xml file of each application. Take the calculator as an example.

 
 
  1. < ?xml version="1.0" encoding="utf-8"?> 
  2. < manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  3. package="com.android.calculator2"> 
  4. < application android:label="@string/app_name" 
    android:icon="@drawable/icon"> 
  5. < activity android:name="Calculator" 
  6. android:theme="@android:style/Theme.Black"> 
  7. < intent-filter> 
  8. < action android:name="android.intent.action.MAIN" /> 
  9. < category android:name="android.intent.category.LAUNCHER" /> 
  10. < /intent-filter> 
  11. < /activity> 
  12. < /application> 
  13. < /manifest> 

The start method of the calculator is as follows:

 
 
  1. # am start -n com.android.calculator2/com.android.calculator2.Calculator 

For the example project HelloActivity, AndroidManifest. xml is as follows:

 
 
  1. < ?xml version="1.0" encoding="utf-8"?> 
  2. < manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  3. package="com.example.android.helloactivity"> 
  4. < application android:label="Hello, Activity!"> 
  5. < activity android:name="HelloActivity"> 
  6. < intent-filter> 
  7. < action android:name="android.intent.action.MAIN"/> 
  8. < category android:name="android.intent.category.LAUNCHER"/> 
  9. < /intent-filter> 
  10. < /activity> 
  11. < /application> 
  12. < /manifest> 

The Android Command Line Method for starting the program is as follows:

 
 
  1. # am start -n com.example.android.helloactivity/
    com.example.android.helloactivity.HelloActivity 

Other application startup commands are as follows:

Use the following method to start a calendar:

 
 
  1. # am start -n com.android.calendar/com.android.calendar.LaunchActivity 

The startup method of the AlarmClock alarm is as follows:

 
 
  1. # am start -n com.android.alarmclock/com.android.alarmclock.AlarmClock 

The startup method of Music and Video is as follows:

 
 
  1. # am start -n com.android.music/com.android.music.MusicBrowserActivity  
  2. # am start -n com.android.music/com.android.music.VideoBrowserActivity  
  3. # am start -n com.android.music/com.android.music.MediaPlaybackActivity 

Camera) Android command line to start the program method:

 
 
  1. # am start -n com.android.camera/com.android.camera.Camera 

Browser) Android command line to start the program:

 
 
  1. # am start -n com.android.browser/com.android.browser.BrowserActivity 

Generally, an Android Application corresponds to a project. It is worth noting that some projects have multiple activity activities), while some applications use one project. For example, in the Android interface, Music and Video are two applications, but they all use the packages/apps/Music project. The AndroidManifest. xml file of this project contains different activities ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.