{"action":"opened","issue":{"url":"https://api.github.com/repos/googlecodelabs/android-workmanager/issues/97","repository_url":"https://api.github.com/repos/googlecodelabs/android-workmanager","labels_url":"https://api.github.com/repos/googlecodelabs/android-workmanager/issues/97/labels{/name}","comments_url":"https://api.github.com/repos/googlecodelabs/android-workmanager/issues/97/comments","events_url":"https://api.github.com/repos/googlecodelabs/android-workmanager/issues/97/events","html_url":"https://github.com/googlecodelabs/android-workmanager/issues/97","id":364842603,"node_id":"MDU6SXNzdWUzNjQ4NDI2MDM=","number":97,"title":"Work state not showing correctly and cancelAllWorkByTag not cancelling work completely.","user":{"login":"Akshay-Kumar-S","id":24350160,"node_id":"MDQ6VXNlcjI0MzUwMTYw","avatar_url":"https://avatars0.githubusercontent.com/u/24350160?v=4","gravatar_id":"","url":"https://api.github.com/users/Akshay-Kumar-S","html_url":"https://github.com/Akshay-Kumar-S","followers_url":"https://api.github.com/users/Akshay-Kumar-S/followers","following_url":"https://api.github.com/users/Akshay-Kumar-S/following{/other_user}","gists_url":"https://api.github.com/users/Akshay-Kumar-S/gists{/gist_id}","starred_url":"https://api.github.com/users/Akshay-Kumar-S/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Akshay-Kumar-S/subscriptions","organizations_url":"https://api.github.com/users/Akshay-Kumar-S/orgs","repos_url":"https://api.github.com/users/Akshay-Kumar-S/repos","events_url":"https://api.github.com/users/Akshay-Kumar-S/events{/privacy}","received_events_url":"https://api.github.com/users/Akshay-Kumar-S/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-28T11:02:55Z","updated_at":"2018-09-28T11:02:55Z","closed_at":null,"author_association":"NONE","body":"library version used: `android.arch.work:work-runtime:1.0.0-alpha08`\r\nDevices/Android versions reproduced on: Nokia 6.1 Android V8.1.0\r\n\r\nI will mention the steps to reproduce this issue.\r\n\r\nfollowing is my worker class\r\n\r\n    public class SyncWorker extends Worker {\r\n\r\n    @NonNull\r\n    @Override\r\n    public Result doWork() {\r\n        try {\r\n            Log.d(\"mylog\", \"doWork: \");\r\n            try {\r\n                Thread.sleep(60*1000);\r\n            } catch (InterruptedException e) {\r\n                e.printStackTrace();\r\n            }\r\n            Log.d(\"mylog\", \"doWork: thread finished\");\r\n            MyClass myClass = new MyClass();\r\n            myClass.syncDevice();\r\n            return Result.SUCCESS;\r\n        } catch (Exception e) {\r\n            return Result.FAILURE;\r\n        }\r\n    }\r\n    }\r\n\r\nI used `WorkManager.getInstance().enqueue(getInstance());` to start the above worker class. This code is in onCreate() of my Activity. getInstance() is also written in that activity, following is the code.\r\n\r\n    public static OneTimeWorkRequest getInstance() {\r\n        if (workRequest == null) {\r\n            workRequest = new OneTimeWorkRequest.Builder(SyncWorker.class)\r\n                    .addTag(\"check_work\")\r\n                    .build();\r\n        }\r\n        return workRequest;\r\n    }\r\n\r\n\r\nI have two buttons in my activity\r\none is to observe the state, while the other is to cancel the SyncWorker\r\n\r\nAfter started the SyncWorker, I click on my first button, which will observe the worker.\r\nI used getStatusById() and getStatusesByTag() both are in the same button click. mentioning the code below.\r\n\r\n    public void button1(View v) {\r\n            WorkManager.getInstance().getStatusById(getInstance().getId()).observe(this, new Observer<WorkStatus>() {\r\n                @Override\r\n                public void onChanged(@Nullable WorkStatus workStatus) {\r\n                    if (workStatus != null) {\r\n                        Log.e(\"mylog\", \"onOptionsItemSelected: \"+workStatus.getState().name());\r\n                    }\r\n                }\r\n            });\r\n\r\n            WorkManager.getInstance().getStatusesByTag(\"check_work\").observe(this, new Observer<List<WorkStatus>>() {\r\n                @Override\r\n                public void onChanged(@Nullable List<WorkStatus> workStatuses) {\r\n                    if (workStatuses != null && !workStatuses.isEmpty()) {\r\n                        Log.d(\"mylog\", \"onOptionsItemSelected: \"+workStatuses.get(0).getState());\r\n                    } \r\n                }\r\n            });\r\n    }\r\n\r\ngetStatusById() will log work state as RUNNING, at the same time getStatusesByTag() will log state as SUCCEEDED.\r\nWithin that Thread sleep of 1min, I clicked second button to cancel my work and the observer getStatusById() will log work state as CANCELLED and getStatusesByTag() will log state as SUCCEEDED.\r\nI didn't get any other state other than SUCCEEDED using getStatusesByTag() (code mentioned above) While the other (getStatusById()) will log correct status.\r\n\r\nI cancelled my worked within that thread sleep 1min, but the code after the sleep (mentioned below or check syncWorker class) executed after that sleep.\r\n   `MyClass myClass = new MyClass();\r\n   myClass.syncDevice();`\r\n\r\n"}}
{"actor":{"display_login":"Akshay-Kumar-S"}}