NetworkOnMainThreadException in Service

前端 未结 4 1412
渐次进展
渐次进展 2021-01-19 19:15

I\'m getting a NetworkOnMainThreadException in my Service class, which by nature doesn\'t make sense, because Services are background processes as

4条回答
  •  长发绾君心
    2021-01-19 19:41

    i just resolve this problem by using this :

    public int onStartCommand(Intent intent, int flags, int startId) {
    
        RefreshDBAsync task = new RefreshDBAsync(this);
        task.execute();
    
        return START_STICKY;
    }
    

    RefreshDBAsync is making request to a server at every 5 minutes

提交回复
热议问题