Stopped Service is Doing Constant Garbage Collection

后端 未结 3 2023
野性不改
野性不改 2020-12-15 17:32

I am developing an application which has many services. When I stop the intent service, all threads and service should be stopped but the UI is hung and the following errors

3条回答
  •  再見小時候
    2020-12-15 18:24

    Same problem also occured for me. But I am using SqLite. When I want to select List of my entity I forgot to add some important methods. When problem occured my code is following

     public List getBlockeds() {
        List blockeds = new ArrayList<>();
        String[] allColumns = {"id", "phoneNumber"};
        Cursor cursor = database.query("Blockeds", allColumns, null, null, null, null, "id desc");
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            Blocked blocked = new CursorToPojo().cursorToBlocked(cursor);
            blockeds.add(blocked);
        }
        return blockeds;
    }
    

    When change code to following the problem solved.

    public List getBlockeds() {
        List blockeds = new ArrayList<>();
        String[] allColumns = {"id", "phoneNumber"};
        Cursor cursor = database.query("Blockeds", allColumns, null, null, null, null, "id desc");
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            Blocked blocked = new CursorToPojo().cursorToBlocked(cursor);
            blockeds.add(blocked);
            cursor.moveToNext();
        }
        cursor.close();
        return blockeds;
    }
    

    I realised that when I did not use cursor.moveToNext cursor never end and the preceding problem start.

提交回复
热议问题