-2

I have a classe for download files by an executor :

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();



        }

In this methode i have an IntentService(mServiceIntent) for handle a long treatement on my download. My executor class handle intentService like this in switch command :

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;

mServiceIntent Class is :

public class TraitementPermisLoaded extends IntentService {


static final String LOG_TAG = "ewp-executor ";
SharedPreferences sharedPreferences;
Handler handler;

public TraitementPermisLoaded() {
    super("TraitementPermisLoaded");
    setIntentRedelivery(true);
    Log.i(LOG_TAG," service traitement permis called 2 ");
}

@Override
protected void onHandleIntent(Intent workIntent) {
    this.sharedPreferences = getApplicationContext().getSharedPreferences("DATA", Context.MODE_PRIVATE);
    // Gets data from the incoming Intent
    String responseData = workIntent.getDataString();
    Messenger messenger = null;
    String ptUuid = "";
    Bundle extras=workIntent.getExtras();
    if (extras!=null) {
        messenger=(Messenger)extras.get("myHandler");
        ptUuid = extras.getString("ptUuid");

    }
    String permisUuid = "";
    PtWrapper pt = null;
    try {

        ObjectMapper mapper = new ObjectMapper();
        pt = mapper.readValue(responseData, PtWrapper.class);

        HandleJson handleJson = HandleJson.getInstance(getApplicationContext());
        permisUuid = pt.getPermisTravailFormContext().permisTravail.uuid;
        if (permisUuid != null) {
            handleJson.writeInInterneFileSysteme(sharedPreferences.getString("email",null),pt, permisUuid);
        } else {
            throw new HandleJsonNoPermisException("le UUID est null on ne peut pas enregistrer ce permis");
        }

        handleJson.setKpi(pt);

        Message message = Message.obtain();
        Bundle bundle= new Bundle();
        bundle.putString("myevent", "un permis ok");
        message.setData(bundle);
        messenger.send(message);


    } catch (IOException e) {
        Log.i(LOG_TAG, e.getMessage());
        e.printStackTrace();

        Message message = Message.obtain();
        Bundle bundle= new Bundle();
        bundle.putString("error", ErrorsCodes.CODE_40.toString()+" / permit uuid : "+ptUuid);
        message.setData(bundle);
        try {
            messenger.send(message);
        } catch (RemoteException e1) {
            e1.printStackTrace();
            Log.i(LOG_TAG,"erreur messager : "+e1.getMessage());
        }

    } catch (HandleJsonNoPermisException e) {
        Log.i(LOG_TAG, e.getMessage());
        e.printStackTrace();
    } catch (RemoteException e) {
        Log.i(LOG_TAG,e.getMessage());
        e.printStackTrace();
    }catch(Exception e){
        Log.i(LOG_TAG,e.getMessage());
        e.printStackTrace();
    }

}

}

I load 27 files but only 14 get a treatment, the Intentservice stop to work, it'seems to be after activity change but not sure. After loaded files, I change my activity by another, but intentService get all request in the queue. I have use IntentService because it will finish working all process before stopping?
What did I do wrong?
Thanks

2 Answers2

0

the error source is the size of data in myService.setData(mydata>250ko). For all data more than 250 ko the service stop with this error message :

A/ActivityManager: Service done with onDestroy, but executeNesting=2: ServiceRecord{5c8e958 u0 com.alit.aws.android.eworkpermit/.lib.TraitementPermisLoaded

There is another way to pass large data more than 250 k to my intentService ? I have tried :
->mServiceIntent.setData(Uri.parse(responseData)); ->mServiceIntent.putExtra("myData",responseData);

0

I have found a solution, remove the "setData(responseData)" and replace it by a globalHasMap. After the end of treatment I remove item in hashMap.
May be it's not awesome but i have not found a better solution. If someone can show me a better way, do it ;-)
Thanks