Intent_Filter Action 在 AndroidManifest 中不起作用
我有一个活动,它还必须收听来自自制服务的特定广播。 我注意到,当我将其添加为 Androidmanifest 文件中的操作时,应用程序在调试时实际上不会启动。 该活动也是我的主要活动:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
但是当我向其中添加自己的额外操作时,它根本不会接收广播,并且在调试时不会自行启动???
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="development.android.service.musicServiceUpdate">
</intent-filter>
知道这里出了什么问题或者为什么我的活动不会收到广播吗? 是否可以为 .MAIN 操作指定两个操作?
/编辑:
尝试以下操作:
<activity android:name=".nowPlayingGUI"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".nowPlayingGUI">
<intent-filter>
<action android:name="development.android.service.musicServiceUpdate"></action>
</intent-filter>
</receiver>
这不起作用,并且会抛出:
10-14 11:57:04.412: ERROR/AndroidRuntime(11947): java.lang.RuntimeException: 无法实例化接收器development.android.myPlayer.nowPlayingGUI :java.lang.ClassCastException:development.android.myplayer.nowPlayingGUI
10-14 11:57:04.412:错误/AndroidRuntime(11947):在android.app.ActivityThread.handleReceiver(ActivityThread.java:2520)
I have an Activity which also has t olisten to a specific broadcast from a self-made service.
I have noticed though that when I add that as an action to my Androidmanifest file the app won't actually start whilst debugging.
The Activity is also my MAIN activity :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
But when I add my own extra action to it it simply wont pick up the broadcast and it won't start up out of itself whilst debugging ????
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="development.android.service.musicServiceUpdate">
</intent-filter>
Any idea whats wrong here or why my activity wont be catching the broadcast ?
Is it possible to have two action's specified to a .MAIN action ?
/edit :
Tried the following :
<activity android:name=".nowPlayingGUI"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".nowPlayingGUI">
<intent-filter>
<action android:name="development.android.service.musicServiceUpdate"></action>
</intent-filter>
</receiver>
That won't work and will throw a :
10-14 11:57:04.412: ERROR/AndroidRuntime(11947): java.lang.RuntimeException: Unable to instantiate receiver development.android.myPlayer.nowPlayingGUI: java.lang.ClassCastException: development.android.myplayer.nowPlayingGUI
10-14 11:57:04.412: ERROR/AndroidRuntime(11947): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2520)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚遇到了同样的问题。尝试将该意图过滤器中的操作顺序更改为:
I just hit this same problem. Try changing the order of the actions in that intent-filter to this:
每个意图过滤器只能有一个操作(但可以有多个类别)。相反,添加一个额外的意图过滤器。
You can only have one action per intent filter (but you can have multiple categories). Add an additional intent filter instead.
您是否在 androidmanifest.xml 中添加了标签
假设您有一个活动和一个广播接收器,我认为您的清单 xml 将在您的应用程序标签中包含与此类似的内容:
Have you added the tag in your androidmanifest.xml
Assuming you have an activity and a broadcast receiver, I think your manifest xml would contain something similar to this inside your app tag: