public class MyService extends Service{
@Override
public void onCreate(){
Notification notification = new Notification(R.drawable.ic_launcher,"您有一条新通知",System.currentTimeMillis());
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, "标题", "内容", pendingIntent);
startForeground(1, notification); //开启前台服务
Log.e("WER", "onCreate");
}
@Override
public void onDestroy(){
stopForeground(true);
Log.e("WER", "onDestroy");
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
public void getData(){
Intent intent = new Intent(this,MyService.class);
this.startService(intent);
}
}