склепал с нескольких уроков с сайта)
в логи кидает onCreate, а дальше не идет)
Код: Выделить всё
package com.odahovskiy.tamagochi;
import java.util.concurrent.TimeUnit;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class TamagochiTimeService extends Service {
NotificationManager nm;
final String LOG_TAG = "myLogs";
public void onCreate() {
super.onCreate();
Log.d(LOG_TAG, "MyService onCreate");
}
public void onDestroy() {
super.onDestroy();
Log.d(LOG_TAG, "MyService onDestroy");
}
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(LOG_TAG, "MyService onStartCommand");
readFlags(flags);
MyRun mr = new MyRun();
new Thread(mr).start();
return START_STICKY;
}
public IBinder onBind(Intent arg0) {
return null;
}
void readFlags(int flags) {
if ((flags&START_FLAG_REDELIVERY) == START_FLAG_REDELIVERY)
Log.d(LOG_TAG, "START_FLAG_REDELIVERY");
if ((flags&START_FLAG_RETRY) == START_FLAG_RETRY)
Log.d(LOG_TAG, "START_FLAG_RETRY");
}
class MyRun implements Runnable {
int count = 0 ;
public MyRun() {
Log.d(LOG_TAG, "MyRun# create");
}
public void run() {
Log.d(LOG_TAG, "MyRun# start");
while(true)
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
void print(){
Log.d(LOG_TAG, ""+count++);
}
void stop() {
}
}
}