実行結果
12-19 06:51:44.123: D/タグ(5143): onCreate
12-19 06:51:44.123: D/タグ(5143): onStart
12-19 06:51:44.292: D/タグ(5143): onDestroy
package com.android.my.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class AdnroidServiceTestActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);//アックティビティーに追加
Intent intent = new Intent(this, MyService.class);
startService(intent);
}
}
package com.android.my.test;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO 自動生成されたメソッド・スタブ
return null;
}
public void onCreate() {
Log.d("タグ", "onCreate");
}
public void onStart(Intent intent, int StartId) {
Log.d("タグ", "onStart");
stopSelf();
}
public void onDestroy() {
Log.d("タグ", "onDestroy");
}
}
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.my.test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".AdnroidServiceTestActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name="MyService" > </service> </application> </manifest>
0 件のコメント:
コメントを投稿