Merhaba arkadaşlar bir önceki yazımda bahsettiğim gibi şimdi ise basit kullanımına dail bir örnek yapacağım

public class LocalService extends Service
{
private static Timer timer = new Timer();
private Context ctx;
public IBinder onBind(Intent arg0)
{
return null;
}
public void onCreate()
{
super.onCreate();
ctx = this;
startService();
}
private void startService()
{
timer.scheduleAtFixedRate(new mainTask(), 0, 5000);
}
private class mainTask extends TimerTask
{
public void run()
{
toastHandler.sendEmptyMessage(0);
}
}
public void onDestroy()
{
super.onDestroy();
Toast.makeText(this, “Service Stopped …”, Toast.LENGTH_SHORT).show();
}
private final Handler toastHandler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
Toast.makeText(getApplicationContext(), “test”, Toast.LENGTH_SHORT).show();
}
};
}

 

—————————————————————————
 public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startService(new Intent(RingerSchedule.this, LocalService.class));
}
Bir de manifestte