Android Manifest- intent filter and activity

前端 未结 3 2103
轻奢々
轻奢々 2021-02-13 01:46

Could someone explain the following lines in the manifest -

    
           


        
3条回答
  •  情深已故
    2021-02-13 02:19

    android:name=".AboutUs"
    

    This is the name of your Activity class, the dot at the front is shorthand notation for your package. So this actually stands for com.your.package.name.AboutUs which means your java file that represents this Activity is called AboutUs.java

    android:label="@string/app_name"
    

    label is the string that gets shown in the launcher(if the activity is listed in the launcher) and at the top of the window when the activity is open.

     ... 
    

    intent filter defines the Intents that your activity "listens for" in order to launch.

    
    
    

    Action and category are both fields that get set on an Intent before it is "fired off" into the system. The system will then look for any activities that match both the action and category and if it finds one then it will launch that activity, or if it finds multiple it will show the user all of them and let them pick.

    In your case your the action you are listening for com.example.app1.ABOUT is a custom action that is specific to your app, not one of the systems actions.

    So here is what an intent that would start this particular activity might look like:

    Intent i = new Intent();
    i.setAction("com.example.app1.ABOUT");
    i.addCategory("android.intent.category.DEFAULT");
    startActivity(i);
    

    Note that because you've created a custom action, this intent does not require access to your AboutUs.class so this intent could technically be fired from any app on the device and it would launch into your activity.

提交回复
热议问题