IntentService在执行程序中丢失了工作

时间:2018-04-25 14:41:13

标签: android intentservice android-intentservice

我有一个执行者下载文件的classe:

server <- function(input, output, session) {

  output$dateSelect <- renderUI({
    switch(input$input_type,
           "Date" = dateRangeInput("dateInput", "Dates:",
                                   min=min(wikiraw$incident_date), max = max(wikiraw$incident_date),
                                   start = min(wikiraw$incident_date), end = max(wikiraw$incident_date)),
           "Presidency" = checkboxGroupInput("president", "Presidency", 
                                             choices = levels(wikiraw$presidency),
                                             selected = "President1"))
  })

  output$typeSelect <- renderUI({
    selectInput("type", "Incident type", 
                choices = unique(wikiraw$incident_type), multiple = TRUE, 
                selected = wikiraw$incident_type[1])})

  output$backgroundSelect <- renderUI({
    checkboxGroupInput("background", "Incident background", 
                       choices = unique(wikiraw$incident_background),
                       selected = wikiraw$incident_background[1])})


  selected <- reactive({
    wikiagg <- wikiraw %>% group_by(ID_2, incident_date, incident_type, incident_background, presidency) %>%
      summarize(sum_event = sum(event))
    if(input$input_type=="Date"){wikiagg <- filter(wikiagg,
                                                   incident_date >= min(input$dateInput),
                                                   incident_date <= max(input$dateInput),
                                                   incident_type%in%input$type,
                                                   incident_background%in%input$background)}
    if(input$input_type=="Presidency"){wikiagg <- filter(wikiagg,
                                                         incident_type%in%input$type,
                                                         incident_background%in%input$background,
                                                         presidency%in%input$president)}

    wikiagg <- wikiagg %>% group_by(ID_2) %>%
      summarize(sum_event = sum(sum_event))
    wikiagg
  })

  output$mymap <- renderLeaflet({

    leaflet() %>% 
      addTiles() %>% 
      setView(mean(wikbounds[1,]),
              mean(wikbounds[2,]),
              zoom=6
      )
  })

  observe({
    if(!is.null(input$dateInput)){
      shapefile@data <- left_join(shapefile@data, selected(), by="ID_2")

      ##Define palette across range of data
      wikiaggpal <- wikiraw %>% group_by(ID_2) %>%
        summarize(sum_event = sum(event))
      pal <- colorBin("YlOrRd", wikiaggpal$sum_event, bins=5, na.color = "#bdbdbd")


      leafletProxy("mymap", data = shapefile) %>%
        addTiles() %>% 
        clearShapes() %>% 
        addPolygons(data = shapefile, fillColor = ~pal(sum_event), fillOpacity = 0.7, 
                    color = "white", weight = 2)
    }})
}
shinyApp(ui, server)

在这个方法中,我有一个IntentService(mServiceIntent)来处理我下载的长期处理。我的执行器类在switch命令中处理这样的intentService:

this.getFreshGoolgletoken(new CallBackTokenRefresh() {

        @Override
        public void getFreshGoogleToken(String token,String userEmail) {

            ArrayList<ExecuteSynchroneRequest> mesRequetes = new ArrayList<>();
            Intent mServiceIntent = new Intent(context, TraitementPermisLoaded.class);

            for (CollectionPermis permis : collectionPermis){
                // stocker les permis + les s3Key
                int revision = permis.revision;
                final String uuid = permis.uuid;
                Log.i(LOG_TAG,"synchro OnLoop permis num & revision  :"+uuid+"/"+revision);
                Map<String,String> params = new HashMap<>();
                params.put("uuid",uuid);
                params.put("revision",String.valueOf(revision));

                mesRequetes.add(new ExecuteSynchroneRequest(AwsEworkPermitsRoutes.PERMITS,params,context,token,apiClient,uuid,handler,mServiceIntent,callBack));
            }

            ExecutorService execute = Executors.newSingleThreadExecutor();



            for(Runnable r : mesRequetes){

                 execute.execute(r);

            }



            execute.shutdown();



        }

mServiceIntent Class是:

case PERMITS:
                    if(mServiceIntent == null) break;

                    mServiceIntent.setData(Uri.parse(responseData));
                    mServiceIntent.putExtra("myHandler", new Messenger(handler));
                    mServiceIntent.putExtra("ptUuid", uuid);
                    context.startService(mServiceIntent);
                    break;

我加载了27个文件但只有14个得到了处理,Intentservice停止工作,它似乎是在活动改变之后但不确定。加载文件后,我将另一个文件更改为活动,但intentService获取队列中的所有请求。我使用过IntentService,因为它会在停止之前完成所有进程的工作吗? 我做错了什么? 感谢

2 个答案:

答案 0 :(得分:0)

错误源是myService.setData(mydata&gt; 250ko)中数据的大小。对于超过250 ko的所有数据,服务将停止并显示以下错误消息:

  

A / ActivityManager:使用onDestroy完成的服务,但executeNesting = 2:   ServiceRecord {5c8e958 u0   com.alit.aws.android.eworkpermit / .lib.TraitementPermisLoaded

还有另一种方法可以将超过250 k的大数据传递给我的intentService吗?我试过了:
- &GT; mServiceIntent.setData(Uri.parse(responseData)); - &GT; mServiceIntent.putExtra(&#34; myData的&#34;,responseData);

答案 1 :(得分:0)

我找到了解决方案,删除了“setData(responseData)”并将其替换为globalHasMap。处理结束后,我删除hashMap中的项目 可能它不是很棒但我没有找到更好的解决方案。 如果有人能告诉我一个更好的方法,那就去做吧;-)
感谢