0
我有一個簡單的服務,但似乎並沒有啓動,因爲既不是我Log
已經顯示在logcat
的Android服務沒有啓動
public class MyService extends Service {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Log.d("ID", "Y");
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
Log.d("S", "Y");
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
}
我打電話像這樣的服務:
Intent service = new Intent(this, MyService.class);
startService(service);
的mainfest是:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.servicetutorials"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.servicetutorials.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyService"
android:icon="@drawable/ic_launcher"
android:label="label" >
</service>
</application>
</manifest>
什麼我做錯了嗎?
它的工作原理,非常感謝。 – user2387331
非常高興提供幫助:D – MDMalik
(B)中是否有拼寫錯誤? 'Activity.this'導致我編譯器錯誤。 – Ponkadoodle