无法启动服务意图:未找到 [英] Unable to start service Intent: not found
问题描述
我有同样的问题描述<一个href=\"http://stackoverflow.com/questions/3439356/unable-to-start-service-intent/19105337#19105337\">here但我不能什么错明白。
我的问题是:无法启动服务意向{行动= .connections.MoodyService} U = 0:未找到
修改
*的我已经改变了我的包,从连接源$ C $ C到服务,遗憾的混乱的*
我的清单`
&LT;清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.moody
安卓的installLocation =自动
安卓版code =0
机器人:=的versionName0.6.7阿尔法&GT;&LT;用途-SDK
机器人:maxSdkVersion =18
安卓的minSdkVersion =14
机器人:targetSdkVersion =17/&GT;&LT;使用许可权的android:NAME =android.permission.INTERNET对/&GT;
&LT;使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/&GT;
&LT;使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE/&GT;&lt;应用
机器人:allowBackup =真
机器人:allowClearUserData =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme&GT;
&LT;活动
机器人:名字=activities.MainActivity
机器人:标签=@字符串/ APP_NAME&GT;
&LT; /活性GT;
&LT;活动
机器人:名字=activities.Menu_esq
机器人:标签=@字符串/ title_activity_menu_esq&GT;
&LT; /活性GT;
&LT;活动
机器人:名字=activities.BaseActivity
机器人:标签=@字符串/ title_activity_base&GT;
&LT; /活性GT;
&LT;活动
机器人:名字=activities.MainView
机器人:标签=@字符串/ title_activity_main_view&GT;
&LT; /活性GT;
&LT;活动
机器人:名字=activities.LoginActivity
机器人:标签=@字符串/ APP_NAME
机器人:noHistory =真
机器人:windowSoftInputMode =adjustResize | stateVisible&GT;
&所述;意图滤光器&gt;
&lt;作用机器人:名字=android.intent.action.MAIN/&GT; &LT;类机器人:名字=android.intent.category.LAUNCHER/&GT;
&所述; /意图滤光器&gt;
&LT; /活性GT;
&LT;活动
机器人:名字=com.example.moody.LeftActivity
机器人:标签=@字符串/ title_activity_left&GT;
&LT; /活性GT;
&LT;活动
机器人:名字=com.example.moody.RightActivity
机器人:标签=@字符串/ title_activity_right&GT;
&LT; /活性GT;
&LT;活动
机器人:名字=activities.UserDetailsActivity
机器人:标签=@字符串/ title_activity_user_details&GT;
&LT; /活性GT;
&LT;活动
机器人:名字=fragments.Topics preVIEW
机器人:标签=@字符串/ title_activity_copy_of_topics_ preVIEW&GT;
&LT; /活性GT;
&LT;活动机器人:名字=activities.Loading&GT;
&LT; /活性GT; &LT;服务
机器人:service.MoodyServiceNAME =
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ moody_service&GT;
&LT; /服务&GT;
&LT; /用途&gt;
服务包和MoodyService是类的名字
我的服务类
公共类MoodyService延伸服务{公共MoodyService(){
// TODO自动生成构造函数存根
}私人布尔isRunning = FALSE;
对象的getContent;@覆盖
公众的IBinder onBind(意向意图){
// TODO自动生成方法存根 返回null;
}@覆盖
公共无效的onCreate(){
super.onCreate();
}@覆盖
公众诠释onStartCommand(意向意图,诠释标志诠释startId){
super.onStartCommand(意向,旗帜,startId); //有关启动公告
Toast.makeText(这一点,启动演示服务,Toast.LENGTH_SHORT)
。显示(); //启动一个后台线程
isRunning = TRUE;
螺纹backgroundThread =新主题(新BackgroundThread());
backgroundThread.start(); //我们希望该服务继续运行,直到它被明确
//停止,因此返回粘。
返回START_STICKY;
}@覆盖
公共无效的onDestroy(){
super.onDestroy(); //停止后台线程
isRunning = FALSE; //有关停止公告
Toast.makeText(这一点,停止演示服务,Toast.LENGTH_SHORT)
。显示();
}私有类BackgroundThread实现Runnable {
INT计数器= 0; 公共无效的run(){
尝试{
计数器= 0;
而(isRunning){
的System.out.println(+专柜+);
新内容()。GETALL(getResources()
getApplicationContext());
Thread.currentThread()睡眠(5000)。
} 的System.out.println(后台线程完成.........);
}赶上(例外五){
e.printStackTrace();
}
}
}
,并在我的主。
意图开始=新意图(service.MoodyService。);
this.startService(开始);
和也试过
意向意图=新意图(这一点,MoodyService.class);
this.startService(意向);
和完整路径尝试
&LT;服务
机器人:名字=com.example.moody.service.MoodyService
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ moody_service&GT;
解决
我删除了清单中的包名称的开头周期,它的工作,换句话说:
这不工作:
.yourPackage.YourClass
但是,这不会工作:
yourPackage.YourClass
和主:
意向意图=新意图(这一点,MoodyService.class);
this.startService(意向);
但它违背了什么是写在文档:
的android:名称实现服务的服务子类的名称。这应该是一个完全合格的类名(例如,
com.example.project.RoomService)。然而,作为一个速记,如果
名称的第一个字符是一个周期(例如,.RoomService),
它被附加到指定的软件包名称
元件。一旦你发布你的应用程序时,你不应该改变这种
名字(除非你设置的android:出口=假)。
块引用>有没有缺省值。该名称必须指定。
I've the same issue described here but i can't understand whats wrong.
My issue is: Unable to start service Intent { act=.connections.MoodyService } U=0: not found
EDIT *I've changed my package from connections to service in the source code, sorry for the confusion*
My manifest`
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.moody" android:installLocation="auto" android:versionCode="0" android:versionName="0.6.7 alpha" > <uses-sdk android:maxSdkVersion="18" android:minSdkVersion="14" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:allowClearUserData="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="activities.MainActivity" android:label="@string/app_name" > </activity> <activity android:name="activities.Menu_esq" android:label="@string/title_activity_menu_esq" > </activity> <activity android:name="activities.BaseActivity" android:label="@string/title_activity_base" > </activity> <activity android:name="activities.MainView" android:label="@string/title_activity_main_view" > </activity> <activity android:name="activities.LoginActivity" android:label="@string/app_name" android:noHistory="true" android:windowSoftInputMode="adjustResize|stateVisible" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.example.moody.LeftActivity" android:label="@string/title_activity_left" > </activity> <activity android:name="com.example.moody.RightActivity" android:label="@string/title_activity_right" > </activity> <activity android:name="activities.UserDetailsActivity" android:label="@string/title_activity_user_details" > </activity> <activity android:name="fragments.TopicsPreview" android:label="@string/title_activity_copy_of_topics_preview" > </activity> <activity android:name="activities.Loading" > </activity> <service android:name=".service.MoodyService" android:icon="@drawable/ic_launcher" android:label="@string/moody_service" > </service> </application>
service is the package and MoodyService is the class name
My service class
public class MoodyService extends Service { public MoodyService() { // TODO Auto-generated constructor stub } private boolean isRunning = false; Object getContent; @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); // Announcement about starting Toast.makeText(this, "Starting the Demo Service", Toast.LENGTH_SHORT) .show(); // Start a Background thread isRunning = true; Thread backgroundThread = new Thread(new BackgroundThread()); backgroundThread.start(); // We want this service to continue running until it is explicitly // stopped, so return sticky. return START_STICKY; } @Override public void onDestroy() { super.onDestroy(); // Stop the Background thread isRunning = false; // Announcement about stopping Toast.makeText(this, "Stopping the Demo Service", Toast.LENGTH_SHORT) .show(); } private class BackgroundThread implements Runnable { int counter = 0; public void run() { try { counter = 0; while (isRunning) { System.out.println("" + counter++); new Contents().getAll(getResources(), getApplicationContext()); Thread.currentThread().sleep(5000); } System.out.println("Background Thread is finished........."); } catch (Exception e) { e.printStackTrace(); } } }
And in my main.
Intent start = new Intent(".service.MoodyService"); this.startService(start);
and also tried
Intent intent = new Intent(this, MoodyService.class); this.startService(intent);
and tried with the full path
<service android:name="com.example.moody.service.MoodyService" android:icon="@drawable/ic_launcher" android:label="@string/moody_service" >
解决方案Solved
I deleted the period in the beginning of the package name in the manifest and it worked, in another words:
This doesn't work:
.yourPackage.YourClass
But this does work:
yourPackage.YourClass
And in the main:
Intent intent = new Intent(this, MoodyService.class); this.startService(intent);
But it goes against what is written in the documentation:
android:name The name of the Service subclass that implements the service. This should be a fully qualified class name (such as, "com.example.project.RoomService"). However, as a shorthand, if the first character of the name is a period (for example, ".RoomService"), it is appended to the package name specified in the element. Once you publish your application, you should not change this name (unless you've set android:exported="false").
There is no default. The name must be specified.
这篇关于无法启动服务意图:未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!