我有与
here描述相同的问题,但我不明白是什么错了。
我的问题是:无法启动服务Intent {act = .connections.MoodyService} U = 0:未找到
编辑
*我已将源码中的连接更改为服务,不好意思,
我的清单
package="com.example.moody"
android:installLocation="auto"
android:versionCode="0"
android:versionName="0.6.7 alpha" >
android:maxSdkVersion="18"
android:minSdkVersion="14"
android:targetSdkVersion="17" />
android:allowBackup="true"
android:allowClearUserData="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:name="activities.MainActivity"
android:label="@string/app_name" >
android:name="activities.Menu_esq"
android:label="@string/title_activity_menu_esq" >
android:name="activities.BaseActivity"
android:label="@string/title_activity_base" >
android:name="activities.MainView"
android:label="@string/title_activity_main_view" >
android:name="activities.LoginActivity"
android:label="@string/app_name"
android:noHistory="true"
android:windowSoftInputMode="adjustResize|stateVisible" >
android:name="com.example.moody.LeftActivity"
android:label="@string/title_activity_left" >
android:name="com.example.moody.RightActivity"
android:label="@string/title_activity_right" >
android:name="activities.UserDetailsActivity"
android:label="@string/title_activity_user_details" >
android:name="fragments.TopicsPreview"
android:label="@string/title_activity_copy_of_topics_preview" >
android:name=".service.MoodyService"
android:icon="@drawable/ic_launcher"
android:label="@string/moody_service" >
服务是包,MoodyService是类名
我的服务班
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();
}
}
}
在我的主要
Intent start = new Intent(".service.MoodyService");
this.startService(start);
并试过
Intent intent = new Intent(this, MoodyService.class);
this.startService(intent);
并尝试着全路径
android:name="com.example.moody.service.MoodyService"
android:icon="@drawable/ic_launcher"
android:label="@string/moody_service" >