什么是意向性过滤器的Andr​​oid? [英] What are intent-filters in Android?

查看:423
本文介绍了什么是意向性过滤器的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序,我想开始从最初的活动'A'活动'B'。我创建类这两种。但是使用下面的code启动B计算,我得到一个运行时错误:应用程序已意外停止,请重试。这是我的code:

 意图myIntent =新的意图(这一点,AddNewActivity.class);
startActivity(myIntent);
 

当我加入 AndroidManifest.xml中/清单/应用/活动/意向性文件管理器的新条目的活动B,则该应用程序的工作。

我有两个问题:

  • 当有的Andr​​oidManifest.xml 多个活动项目,如何安卓知道第一次启动?哪个活动
  • 在我无法理解的意图过滤器。任何人都可以请解释一下。

下面是我的部分的Andr​​oidManifest.xml

 <应用机器人:图标=@可绘制/图标机器人:标签=@字符串/ APP_NAME>
    <活动机器人:名称=。ListAllActivity
              机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
    <活动机器人:AddNewActivity名称=机器人:标签=@字符串/ APP_NAME>
        <意向滤光器>
            <作用机器人:名称=android.intent.action.MAIN/>
            <类机器人:名称=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
< /用途>
 

解决方案
  

当有多个活动   在AndroidManifest.xml中,如何项   没有安卓知道哪些活动   第一次启动?

没有第一。在你的情况,你的表现如图所示,你会在你的发射两个图标。哪一个用户点击的是,被推出的。

  

我不明白的意图过滤器。   任何人都可以请解释一下。

有关于这个问题相当多的文档。请考虑阅读的,然后问更具体的问题。

此外,当你拿到应用程序已意外停止,请重试,使用亚行logcat ,DDMS或DDMS透视图在Eclipse检查相关的Java堆栈跟踪与错误。

In my android app, I wanted to start an activity 'B' from initial activity 'A'. I have created classes for both of these. However when using following code to start B, I get a runtime error: application has stopped unexpectedly, try again. Here is my code:

Intent myIntent = new Intent(this, AddNewActivity.class);
startActivity(myIntent); 

When I added a new entry in AndroidManifest.xml/manifest/application/activity/intent-filers for activity B then the application worked.

I have two questions:

  • When there are multiple activities entries in AndroidManifest.xml, how does android know which activity to start first?
  • I could not understand intent-filters. Can anyone please explain.

Here is my partial AndroidManifest.xml

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".ListAllActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".AddNewActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

解决方案

When there are multiple activities entries in AndroidManifest.xml, how does android know which activity to start first?

There is no "first". In your case, with your manifest as shown, you will have two icons in your launcher. Whichever one the user taps on is the one that gets launched.

I could not understand intent-filters. Can anyone please explain.

There is quite a bit of documentation on the subject. Please consider reading that, then asking more specific questions.

Also, when you get "application has stopped unexpectedly, try again", use adb logcat, DDMS, or the DDMS perspective in Eclipse to examine the Java stack trace associated with the error.

这篇关于什么是意向性过滤器的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆