It’s code here:
public class MyServeice extends Service
{
private Timer pushTimer;
private final int NOTEF_ID = 1234;
NotificationManager manager;
@Override
public IBinder onBind(Intent arg0)
{
return null;
}
@Override
public void onCreate()
{
Log.i("MyActivity", "1");
//pushTimer = new Timer();
manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
@Override
public void onDestroy()
{
Log.i("MyActivity", "2");
//pushTimer.cancel();
}
@Override
public void onStart(Intent intent, int startid)
{
Log.i("MyActivity", "3");
//pushTimer.schedule(new TimerTask()
//{
// @Override
// public void run()
// {
Notification not = new Notification(R.drawable.ic_launcher, "Custom notification", System.currentTimeMillis());
PendingIntent notIntent = PendingIntent.getActivity(this , 0, new Intent(this, MainActivity.class), 0);
not.setLatestEventInfo(this, "Title", "Text", notIntent);
manager.notify(NOTEF_ID, not);
manager.cancel(NOTEF_ID);
// }
//}, 0L, 60L * 1000);
}
}
I try to start it from my MainActivity activity class (before I thought that problem is in timer, but now I comment it).
Starting code here:
startService(new Intent(this, MyServeice.class));
Log from Service class is not shown, so I decided that Service is not started at all. Application doesn’t crash and started normaly. Can you check my code?
You made a mistake in MyServeice Class
You use
& in Service Life cycle there is no onStart(..) Method
Try this method instead of above
EDIT:
& second One you have to declare service in Manifest File Like:
For more Information About Service Refer this Documentation
http://developer.android.com/guide/components/services.html