上次,我使用以下代码来运行后台服务。
为了提高性能,我希望在设备连接WIFI/数据连接时运行我的后台服务。换言之,如果设备没有连接WIFI/数据连接,我的后台服务肯定不会运行。一旦连接WIFI/数据连接,它将立即运行。
Intent intent = new Intent(InitActivity.this, GetService.class);
PendingIntent pintent = PendingIntent.getService(InitActivity.this, 0, intent, 0);
Calendar calendar = Calendar.getInstance();
AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 50 * 1000, pintent);
return getZipInfo.toString();
为了提高性能,我希望在设备连接WIFI/数据连接时运行我的后台服务。换言之,如果设备没有连接WIFI/数据连接,我的后台服务肯定不会运行。一旦连接WIFI/数据连接,它将立即运行。