{"id":22017744,"url":"https://github.com/myinnos/android-workmanager","last_synced_at":"2026-04-20T13:34:14.557Z","repository":{"id":80788184,"uuid":"383086668","full_name":"myinnos/android-workmanager","owner":"myinnos","description":"Android WorkManager Example","archived":false,"fork":false,"pushed_at":"2021-07-05T10:38:52.000Z","size":142,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T09:34:11.872Z","etag":null,"topics":["android","workmanager"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/myinnos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-05T09:33:22.000Z","updated_at":"2021-08-26T20:40:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"bcdc40fd-25af-440f-bdff-c795f3f6cb0e","html_url":"https://github.com/myinnos/android-workmanager","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/myinnos/android-workmanager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myinnos%2Fandroid-workmanager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myinnos%2Fandroid-workmanager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myinnos%2Fandroid-workmanager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myinnos%2Fandroid-workmanager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/myinnos","download_url":"https://codeload.github.com/myinnos/android-workmanager/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/myinnos%2Fandroid-workmanager/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263795090,"owners_count":23512639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","workmanager"],"created_at":"2024-11-30T05:07:42.722Z","updated_at":"2026-04-20T13:34:09.514Z","avatar_url":"https://github.com/myinnos.png","language":"Java","readme":"# Android Workmanager\n\nWhat is WorkManager?\nWorkManager is part of Android Jetpack. WorkManager helps us to execute our tasks immediately or an appropriate time.\n\nEarlier we had AlarmManager, JobScheduler, FirebaseJobDispatcher for scheduling the background tasks. But the issues were\n\nAnd it is very simple, just go to app level build.gradle file and add the following implementation line.\n \n    implementation \"android.arch.work:work-runtime:1.0.1\"\n        \n \nFor creating a worker we need to create a class and then in the class we need to extend Worker. So here I am creating a class named MyWorker.\n\n \n    import android.app.NotificationChannel;\n    import android.app.NotificationManager;\n    import android.content.Context;\n    import android.support.annotation.NonNull;\n    import android.support.v4.app.NotificationCompat;\n \n    import androidx.work.Worker;\n    import androidx.work.WorkerParameters;\n \n    public class MyWorker extends Worker {\n \n    public MyWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {\n        super(context, workerParams);\n    }\n \n    /*\n    * This method is responsible for doing the work\n    * so whatever work that is needed to be performed\n    * we will put it here\n    * \n    * For example, here I am calling the method displayNotification()\n    * It will display a notification\n    * So that we will understand the work is executed \n    * */\n    \n    @NonNull\n    @Override\n    public Result doWork() {\n        displayNotification(\"My Worker\", \"Hey I finished my work\");\n        return Result.sucess();\n    }\n \n    /*\n    * The method is doing nothing but only generating \n    * a simple notification\n    * If you are confused about it\n    * you should check the Android Notification Tutorial\n    * */\n    private void displayNotification(String title, String task) {\n        NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);\n \n        if (android.os.Build.VERSION.SDK_INT \u003e= android.os.Build.VERSION_CODES.O) {\n            NotificationChannel channel = new NotificationChannel(\"simplifiedcoding\", \"simplifiedcoding\", NotificationManager.IMPORTANCE_DEFAULT);\n            notificationManager.createNotificationChannel(channel);\n        }\n \n        NotificationCompat.Builder notification = new NotificationCompat.Builder(getApplicationContext(), \"simplifiedcoding\")\n                .setContentTitle(title)\n                .setContentText(task)\n                .setSmallIcon(R.mipmap.ic_launcher);\n \n        notificationManager.notify(1, notification.build());\n      }\n    }    \nNow let’s perform the work that we created. For this first come inside MainActivity.java and write the following code.\n   \n    import android.os.Bundle;\n\n    import androidx.appcompat.app.AppCompatActivity;\n    import androidx.work.Constraints;\n    import androidx.work.Data;\n    import androidx.work.OneTimeWorkRequest;\n    import androidx.work.PeriodicWorkRequest;\n    import androidx.work.WorkManager;\n\n    import java.util.concurrent.TimeUnit;\n\n    import in.myinnos.workmanager.databinding.ActivityMainBinding;\n\n    public class MainActivity extends AppCompatActivity {\n\n    ActivityMainBinding binding;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        binding = ActivityMainBinding.inflate(getLayoutInflater());\n        setContentView(binding.getRoot());\n\n        //creating a data object\n        //to pass the data with workRequest\n        //we can put as many variables needed\n        Data data = new Data.Builder()\n                .putString(MyWorker.TASK_TITLE, \"MyInnos\")\n                .putString(MyWorker.TASK_DESC, \"The task data passed from MainActivity\")\n                .build();\n\n        //creating constraints\n        // you can add as many constraints as you want\n        Constraints constraints =\n                new Constraints.Builder()\n                        .setRequiresCharging(true)\n                        .build();\n\n        // It is needed to perform the work periodically for example taking backup to the server. In scenarios like this we can use PeriodicWorkRequest class.    Everything else is same.\n        // note: PeriodicWorkRequest not working, yet to fix\n        final PeriodicWorkRequest periodicWorkRequest =\n                new PeriodicWorkRequest.Builder(MyWorker.class, 10000, TimeUnit.SECONDS)\n                        .setInputData(data)\n                        .build();\n\n        //This is the subclass of our WorkRequest\n        final OneTimeWorkRequest workRequest =\n                new OneTimeWorkRequest.Builder(MyWorker.class)\n                        .setInputData(data)\n                        .setConstraints(constraints)\n                        .build();\n\n        binding.btEnqueue.setOnClickListener(v -\u003e WorkManager.getInstance().enqueue(workRequest));\n\n        //Listening to the work status\n        WorkManager.getInstance().getWorkInfoByIdLiveData(workRequest.getId())\n                .observe(this, workInfo -\u003e {\n                    //receiving back the data\n                    if (workInfo != null)\n                        binding.txStatus.append(workInfo.getState() + \"\\n\");\n                });\n\n        }\n    }\n \n ##### Any Queries? or Feedback, please let me know by opening a [new issue](https://github.com/myinnos/android-workmanager/issues/new)!\n\n## Contact\n#### Prabhakar Thota\n* :globe_with_meridians: Website: [myinnos.in](http://www.myinnos.in \"Prabhakar Thota\")\n* :email: e-mail: contact@myinnos.in\n* :mag_right: LinkedIn: [PrabhakarThota](https://www.linkedin.com/in/prabhakarthota \"Prabhakar Thota on LinkedIn\")\n* :thumbsup: Twitter: [@myinnos](https://twitter.com/myinnos \"Prabhakar Thota on twitter\")    \n* :camera: Instagram: [@prabhakar_t_](https://www.instagram.com/prabhakar_t_/ \"Prabhakar Thota on Instagram\")   \n\n\u003e If you appreciate my work, consider buying me a cup of :coffee: to keep me recharged :metal: by [PayPal](https://www.paypal.me/fansfolio)\n\nLicense\n-------\n\n    Copyright 2021 MyInnos\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":["https://www.paypal.me/fansfolio"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyinnos%2Fandroid-workmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmyinnos%2Fandroid-workmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmyinnos%2Fandroid-workmanager/lists"}