I am using following code
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;
}
Nothing is happening , the debugger won't even enter in Service. No OnCreate or any other thing getting called.
Probably you don't have the service in your manifest . Examining LogCat (via adb logcat, DDMS, or the DDMS perspective in Eclipse) should turn up some warnings that may help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.