Giter Site home page Giter Site logo

basic-android-kotlin-compose-training-workmanager's Introduction

WorkManager Codelab

This repository contains the code for the WorkManager Codelab.

Introduction

At I/O 2018, Google announced Android Jetpack, a collection of libraries, tools, and architectural guidance to accelerate and simplify the development of great Android apps. One of those libraries is the WorkManager library. The WorkManager library provides a unified API for deferrable one-off or recurring background tasks that need guaranteed execution. You can learn more by reading the WorkManager Guide, the WorkManager Reference or doing the WorkManager Codelab.

Pre-requisites

  • Familiarity with how to open, build, and run apps with Android Studio.

  • Make sure Android Studio is updated, as well as your SDK and Gradle. Otherwise, you may have to wait for a while until all the updates are done.

  • A device or emulator that runs API level 21+

You need to be solidly familiar with the Kotlin programming language, object-oriented design concepts, and Android Development Fundamentals.

In particular:

Getting Started

  1. Install Android Studio, if you don't already have it.
  2. Download the sample.
  3. Import the sample into Android Studio.
  4. Build and run the sample.

Notes:

  • The application code contains a battery not low constraint. If the device/emulator has a low battery, the application will appear to hang until this constraint is met.

  • The app requires notifications to be enabled. To enable notifications, navigate to the Android Settings menu > Apps > Blur-O-Matic > Notifications > Enable "All Blur-O-Matic notifications".

basic-android-kotlin-compose-training-workmanager's People

Contributors

johnshea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

basic-android-kotlin-compose-training-workmanager's Issues

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#5

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
N/A

Describe the problem
dependency is already present in starter code

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Advanced WorkManager and Testing

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-verify-background-work?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-verify-background-work#6

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?

Task 7 - Test with emulator

Describe the problem

In step 1 it is written: "On an emulator, change the Charge level in the Extended Controls window to be 15% or lower to simulate a low battery scenario, Charger connection to AC charger, and Battery status to Not charging". However only when Charger connection is set to "None" (and not to "AC charger") the suggested test works, that is with a battery level below 15% the WorkManager does not run the blurWorker work request

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
_Android Studio version:
Android Studio Koala | 2024.1.1
Build #AI-241.15989.150.2411.11948838, built on June 10, 2024
Runtime version: 17.0.10+0--11609105 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Registry:
ide.experimental.ui=true

_API version of the emulator: 34

Additional information
Include screenshots if they would be useful in clarifying the problem.

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#2

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
run starter code

Describe the problem
it's said that When you click the Start button, the app blurs and saves the image., however, then it's said that Right now, the app does not apply any amount of blur when you click the **Start** button. - the latter is true: selecting a blur amount and clicking Start does not yield any result with the starter code

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Insert Image in the Background Work with WorkManager Codelab

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#10

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
SaveImageToFileWorker -> 3

Describe the problem

In the provided code, notice how the resourceUri and output values are retrieved and stored with the key KEY_IMAGE_URI. This process is very similar to the code you previously wrote for the input and output data objects.

why not guide people step by step through the code by expanding the codelab?

do you really think a beginner will understand the code just by pointing a few facts about the copy paste section?

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#9

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
3

Describe the problem
please improve the code examples

in one code snippet resolver is shown after require(...) { ... } and in the next example it is shown as if it's part of return withContext(Dispatchers.IO) { ... }

the reader can get confused thinking the resolver is inside return@withContext

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#10

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?

Describe the problem
MediaStore.Images.Media.insertImage - insertImage is deprecated in work-runtime-ktx 2.9.0

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#8

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
3

Describe the problem
blur isn't applied

blur-filter-output-5d1f1236-e501-4c5d-bbf7-60328abcbfe2

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Location of the Background Task Inspector

URL of codelab

https://developer.android.com/codelabs/basic-android-kotlin-compose-verify-background-work?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-verify-background-work#3

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
Step 4 - Tag and update the UI based on Work status

Describe the problem

The location of the Background Task Inspector is not mentioned when first introduced. (View > Tool Windows > App Inspection, then "Background Task Inspector" tab)

Alternatively, a tip to check "Debug WorkManager with Background Task Inspector" or move "Debug WorkManager with Background Task Inspector" before Step 4 would resolve the issue.

Schedule tasks with WorkManager Quiz Question 8

URL of codelab

https://developer.android.com/codelabs/basic-android-kotlin-compose-verify-background-work?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-verify-background-work#8

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
Step 9 - Debug WorkManager with Background Task Inspector

Describe the problem

For the end of pathway quiz, question 8 reads "The Background Task Inspector lets you stop workers during their execution.", with the correct answer being "False". However, the documentation in the Advanced WorkManager and Testing states "You can also cancel work using the inspector... Select an enqueued worker and click Cancel Selected Worker ... from the toolbar."

Additional information
Include screenshots if they would be useful in clarifying the problem.

schedule_tasks_with_WorkManager_quiz_question_8
codelab_docuemntation

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#9

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
2

Describe the problem
"passing in the constant BLUR_LEVEL that was used as the"

should be

"passing in the constant KEY_BLUR_LEVEL that was used as the"

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#7

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
2

Describe the problem
imports are in the wrong order

import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import android.content.Context

class BlurWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(ctx, params) {
}

to

import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters

class BlurWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(ctx, params) {
}

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Background Work with WorkManager

URL of codelab

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?

Describe the problem

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be usefuly in clarifying the problem.

Background Work with WorkManager (deprecated code)

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager#10

In which task and step of the codelab can this issue be found?

Describe the problem
Create SaveImageToFileWorker- source code

`package com.example.bluromatic.workers

import ...

/**

  • Saves the image to a permanent file
    */
    private const val TAG = "SaveImageToFileWorker"

class SaveImageToFileWorker(ctx: Context, params: WorkerParameters) : CoroutineWorker(ctx, params) {

...

override suspend fun doWork(): Result {
    ...

    return withContext(Dispatchers.IO) {
        ...
        return@withContext try {
            ...

/*****************************************************************
*** MediaStore.Images.Media.insertImage <- insertImage @deprecated
***************************************************************/
val imageUrl = MediaStore.Images.Media.insertImage(
resolver, bitmap, title, dateFormatter.format(Date())
)
...
} catch (exception: Exception) {
...
}
}
}
}
`
Copie d'écran_20240326_065714

Codelab: Advanced WorkManager and Testing

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-verify-background-work?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-verify-background-work#3
Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
While Saving Image to system

Describe the problem
for SaveImagetoFileWorker, it shows an error in the background data inspector, and the error is the Security Exception because we didn't grant permission for write External Storage and the issue again is from android 13 it is not allowed

Steps to reproduce?

  1. Run the app
  2. Click on the Start button
  3. See error in the background inspector and log cat

Versions
_Android Studio version:_2022.2.1 Patch 2
_API version of the emulator:_32.1.13

Additional information
Include screenshots if they would be useful in clarifying the problem.
image
image

Advanced WorkManager and Testing

URL of codelab

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?

Describe the problem

when app runing , before click start(not running fun applyBlur from viewmodel , outputWorkInfo has value by status succeed ,therefore button seeFile is showing and enable
why?

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Background Work with WorkManager: Issue in conditional block

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#9
Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
Step 10

Describe the problem
//this block will get execute when resource is is not empty or null but inside the block we are
require(!resourceUri.isNullOrBlank()) {
val errorMessage =
applicationContext.resources.getString(R.string.invalid_input_uri)
Log.e(TAG, errorMessage)
errorMessage
}

Steps to reproduce?

  1. Go to : https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#9
  2. Check below code:
    return@withContext try {
    // NEW code
    require(!resourceUri.isNullOrBlank()) {
    val errorMessage =
    applicationContext.resources.getString(R.string.invalid_input_uri)
    Log.e(TAG, errorMessage)
    errorMessage
    }
  3. Error in handling condition

Versions
_Android Studio version: N/A
_API version of the emulator: N/A

Additional information
Screenshot 2023-11-23 at 16 40 44

Include screenshots if they would be useful in clarifying the problem.

Background Work with WorkManager

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-workmanager?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-workmanager#6

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
constraints link directs reader to article with java examples; correct link with kotlin examples is: https://developer.android.com/reference/kotlin/androidx/work/Constraints

Describe the problem

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Codelab: Advanced WorkManager and Testing

Write tests for Worker implementations

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?

Write a BlurWorker test cleanupWorker_doWork_resultSuccess.

Describe the problem

Example test code results in error and does not match final code in main branch.

... 
           assertThat(result, `is`(ListenableWorker.Result.success()))
... 

// main branch
... 
           assertTrue(result is ListenableWorker.Result.Success)
... 

Versions
Android Studio version: 2022.3.1. Patch 2
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

image

Advanced WorkManager and Testing

URL of codelab

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?

Describe the problem

when app runing , before click start(not running fun applyBlur from viewmodel , outputWorkInfo has value by status succeed ,therefore button seeFile is showing and enable
why?

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

No workers in Background Task Inspector, only jobs

URL of codelab
https://developer.android.google.cn/codelabs/basic-android-kotlin-compose-verify-background-work?continue=https%3A%2F%2Fdeveloper.android.google.cn%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-verify-background-work#8

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
9. Debug WorkManager with Background Task Inspector

Describe the problem
As described in the codelab, the workers can be seen in Background Task Inspector "Workers" Tab
But I can't see any workers. I can only see Jobs.
Should I config something in Android Studio?

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version: Electric Eel 2022.1.1 and 2022.1.1 Patch 1
API version of the emulator: 31.3.15

Additional information
Include screenshots if they would be useful in clarifying the problem.
workers

Advanced WorkManager and Testing

URL of codelab
https://developer.android.com/codelabs/basic-android-kotlin-compose-verify-background-work?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-7-pathway-1%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-verify-background-work#7

Specify the language of the codelab if it is not English:

In which task and step of the codelab can this issue be found?
Write a CleanupWorker test: 5

Describe the problem

class WorkerInstrumentationTest {
   private lateinit var context: Context

   @Before
   fun setUp() {
       context = ApplicationProvider.getApplicationContext()
   }

   @Test
   fun cleanupWorker_doWork_resultSuccess() {
   }
}

lacks: create an instance of the CleanupWorker

Steps to reproduce?

  1. Go to...
  2. Click on...
  3. See error...

Versions
Android Studio version:
API version of the emulator:

Additional information
Include screenshots if they would be useful in clarifying the problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.