为什么在Service后台服务中运行一会就网络请求失败

public void onCreate() {
//System.out.println("onCreate");
//--------------------------------------------------------------------------
我的代码在这里,过几秒就发送一个Post
//-------------------------------------------------------------------------
timer.scheduleAtFixedRate(task, 0, 10 * 1000);
super.onCreate();
}
但是过三分钟左右就没网络了,为什么

过一段时间可能OS把你后台进程暂停了,为了节省系统资源

将你的代码放到一个新的线程中试一下。

还有可能就是:
1、你程序的某个地方将后台服务关闭了!

Notification notification = new Notification(R.drawable.ic_launcher, "从此以后,哥也是杀不死的进程了!", 0);

    // 用于启动activity的intent
    Intent intent = new Intent("zz.itcast.cn.huanying.lai.zhengzhou");
    intent.addCategory(Intent.CATEGORY_DEFAULT);

    // PendingIntent 其实就是对一个intent 和这个intent 要干的事,进行包装
    PendingIntent contentIntent = PendingIntent.getActivity(this, 88, intent, PendingIntent.FLAG_ONE_SHOT);
    notification.setLatestEventInfo(this, "", "","", contentIntent);

    // 将服务运行在前台进程
    startForeground(789, notification);

在服务中运行这段代码把当前的服务设置为前台进程

知道为什么了,我用的小米手机测试,有个神隐模式,关掉它就行了,垃圾小米!!!!