Intelligent IntentService Interface

I have one service(BackgoundService), one intent service (MyIntentService)and one processin my android app. the user interface freezes, that is, completely freezes when all three work, but it becomes so responsive when I stop the Intent service.

I also run BackgroundService in a workflow, and the documentation says that the Intent Service runs in a separate workflow by default.

I do not understand why my ui thread is still blocked when all other operations, services are started in separate threads.

Intent Service

     public class MyIntentService extends IntentService {
    public static String ACTION ="com.example.mediaapp.prototypingcanvas.MyIntentService.DONE_Processing";

    public  MyIntentService(){
       super("MyIntentService");
    }
    DBRepo dbRepo;
    WebRepo webRepo;
    FileRepo fileRepo;
    @Override
    protected void onHandleIntent(Intent intent) {

        //Activity Types ; 1=uploadSurvey; 2=downloadQre; 3=download survey for review; 4=sample download; 5=projectlistdownload
        webRepo = new WebRepo(this);
        fileRepo = new FileRepo();
        int queueID = intent.getIntExtra("ID", 0);
        dbRepo = new DBRepo(getApplicationContext());
        dbRepo.updateQueue(queueID);
        List<String> filesList;
        int activityType = intent.getIntExtra("ActivityType", 0);
        // int projectID = intent.getIntExtra("ProjectID",0);
        String userName = intent.getStringExtra("UserName");
        String ProjectGUID = intent.getStringExtra("ProjectGUID");
        String projectName = intent.getStringExtra("ProjectName");

        int response = -1;
        Log.i("activitytype", activityType + "");


        if (activityType == 1) {
            filesList = new ArrayList<>();
            filesList = fileRepo.list(projectName);
            for (String fileName : filesList) {
                webRepo.SyncData("http://test.cloud.rebuscode.com/api/api/v2/respondent/SyncData/" + projectName + "/" + fileName + "/true");
            }
            Log.i("activity type", activityType + "");
            response = 1;
        } else if (activityType == 2) {
            Log.i("activity type", activityType + "");
            response = 0;
        } else if (activityType == 3) {
            Log.i("activity type", activityType + "");
            //webRepo.DownloadQuestionnaire("http://test.cloud.rebuscode.com/api/api/v2/respondent/DownloadQuestionnaireForTab/" + projectGuid + "/" + projectName,projectName);
            fileRepo.unzip("Splash/and.zip");
        } else if (activityType == 4) {
            Log.i("activity type", activityType + "");
            response = 1;
        } else if (activityType == 5) {
            Log.i("activity type", activityType + "");
            response = 0;
        } else {
            Log.i("activity type", activityType + "");
        }

        // processing done here….
        //delete row from Queue table and broadcast
        dbRepo.deleteQueue(queueID);
        Intent broadcastIntent = new Intent(ACTION);
        broadcastIntent.putExtra("Response", response);
        broadcastIntent.putExtra("ActivityType", activityType);
        broadcastIntent.putExtra("UserName", userName);
        broadcastIntent.putExtra("ID", queueID);
        broadcastIntent.putExtra("ProjectGuid", ProjectGUID);
        sendBroadcast(broadcastIntent);

    }
}

can anyone suggest why its blocking my thread u?

+4
source share

Source: https://habr.com/ru/post/1620285/


All Articles