Intent_Filter操作在AndroidManifest中不起作用
我有一个活动,它也包含来自自制服务的特定广播。 虽然我已经注意到,当我将其添加为AndroidManifest文件的操作时,应用程序在调试时不会真正开始。 该活动也是我的主要活动:Intent_Filter操作在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>
这是行不通的,并会抛出:
11月10日至14日:57:04.412:ERROR/AndroidRuntime(11947 ):java.lang.RuntimeException:无法实例化接收器development.android.myPlayer.nowPlayingGUI:java.lang.ClassCastException:development.android.myplayer.nowPlayingGUI
10-14 1 1:57:04.412:错误/ AndroidRuntime(11947):在android.app.ActivityThread.handleReceiver(ActivityThread.java:2520)
每个意图过滤器只能有一个操作(但可以有多个类别)。改为添加一个额外的意图过滤器。
有你在AndroidManifest.xml中
添加标签假设你有一个活动和广播接收器,我想你的清单XML将包含您的应用程序标签内类似这样的东西:
<activity android:name=".Main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name =".myreceiver">
<intent-filter>
<action android:name=development.android.service.musicServiceUpdate />
</intent-filter>
</receiver>
好的,但我的接收器也是.Main类,你建议... – TiGer 2010-10-14 09:10:36
好吧,试过这个,现在当广播应该收到相同的活动它会抛出 10-14 11:57:04.412:错误/ AndroidRuntime(11947):java.lang.RuntimeException:无法实例化接收器development.android.myPlayer.nowPlayingGUI:java.lang.ClassCastException:development.android.myplayer.nowPlayingGUI 10-14 11:57:04.412:ERROR/AndroidRuntime (11947):在android.app.ActivityThread.handleReceiver(ActivityThread。java:2520) – TiGer 2010-10-14 10:00:33
@TiGer:我认为你需要为每个Activity,Service,Broadcast Receiver和Content Provider有不同的类。你必须在清单文件中提到应用程序中有多少活动,接收者,提供者或服务。 – kiki 2010-10-14 10:01:23
我刚刚遇到了同样的问题。尝试更改该意图中的操作顺序 - 过滤器到此:
<intent-filter>
<action android:name="development.android.service.musicServiceUpdate">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
它应该有一个类别?或者是足够的行动? – TiGer 2010-10-14 08:51:20
如果你想添加额外的活动,你至少应该添加“默认”标签。 。如果你想要注册一个广播接收机,那么这个之上的答案就是你要找的。 –
2010-10-14 09:06:30
其实这是完全相同的活动,这应该是主要和也是一个接收器... – TiGer 2010-10-14 09:57:51