我正在使用以下代码
startService(new Intent(Loading.this, AppService.class));
public class AppService extends Service
{
private Timer timer;
@Override
public IBinder onBind(Intent arg0)
{
return null;
}
@Override
public void onCreate()
{
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask()
{
@Override
public void run()
{
SharedPreferences customSharedPreference = getSharedPreferences(
"UserSharedPrefs", Activity.MODE_PRIVATE);
boolean isLoggedIn = customSharedPreference.getBoolean("isLoggedIn", false);
if (isLoggedIn)
updateContact();
}
},0 , 120 * 1000);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
return Service.START_NOT_STICKY;
}
@Override
public void onDestroy()
{
super.onDestroy();
timer.cancel();
timer = null;
}
什么都没有发生,调试器甚至不会进入服务。没有 OnCreate 或任何其他被调用的东西。