

{"id":75209,"date":"2020-01-31T12:17:16","date_gmt":"2020-01-31T06:47:16","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=75209"},"modified":"2021-08-25T13:55:55","modified_gmt":"2021-08-25T08:25:55","slug":"android-service-tutorial","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/","title":{"rendered":"Android Service Tutorial &#8211; Lifecycle, Methods &amp; Implementation"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1202,&quot;href&quot;:&quot;https:\\\/\\\/developer.android.com\\\/reference\\\/java\\\/lang\\\/Thread&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>Ever thought of a music player, as a service? Yes, the music player is a service. Not sure how? Well, it runs in the background while the user happily uses some other application, isn\u2019t it? For a better understanding, consider an online music player that uses the internet and plays music in the background. Now, let&#8217;s understand its technical part.<\/p>\n<h2>What are Android Services?<\/h2>\n<p>Android Services are the application components that run in the background. We can understand it as a process that doesn\u2019t need any direct user interaction. As they perform long-running processes without user intervention, they have no User Interface. They can be connected to other components and do <strong>inter-process communication (IPC)<\/strong>.<\/p>\n<p><em><strong>Did you check the previous\u00a0<a href=\"https:\/\/data-flair.training\/blogs\/android-activity\/\">tutorial on Android activity<\/a>?<\/strong><\/em><\/p>\n<h3>Types of Android Services<\/h3>\n<p>When we talk about services, they can be of three types as shown in the figure below:<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/types-of-android-services.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75234\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/types-of-android-services.jpg\" alt=\"types of android services\" width=\"462\" height=\"396\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/types-of-android-services.jpg 462w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/types-of-android-services-150x129.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/types-of-android-services-300x257.jpg 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/a><\/p>\n<p>The working of these three services is below:<\/p>\n<h4>1. Foreground Services<\/h4>\n<p>Foreground services are those services that are visible to the users. The users can interact with them at ease and track what\u2019s happening. These services continue to run even when users are using other applications.<\/p>\n<p><em>The perfect example of this is Music Player and Downloading.<\/em><\/p>\n<h4>2. Background Services<\/h4>\n<p>These services run in the background, such that the user can\u2019t see or access them. These are the tasks that don\u2019t need the user to know them.<\/p>\n<p><em>Syncing and Storing data can be the best example.<\/em><\/p>\n<h4>3. Bound Services<\/h4>\n<p>Bound service runs as long as some other <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/android-application-components\/\">application component<\/a> <\/strong><\/em>is bound to it. Many components can bind to one service at a time, but once they all unbind, the service will destroy.<\/p>\n<p>To bind an application component to the service, <strong>bindService()<\/strong> is used.<\/p>\n<h3>Lifecycle of Android Services<\/h3>\n<p>Android services life-cycle can have two forms of services and they follow two paths, that are:<\/p>\n<ol>\n<li>Started Service<\/li>\n<li>Bounded Service<\/li>\n<\/ol>\n<p>Let us see these services and their approach.<\/p>\n<h4>1. Started Service<\/h4>\n<p>A service becomes started only when an application component calls <strong>startService()<\/strong>. It performs a single operation and doesn\u2019t return any result to the caller. Once this service starts, it runs in the background even if the component that created it destroys. This service can be stopped only in one of the two cases:<\/p>\n<ul>\n<li>By using the stopService() method.<\/li>\n<li>By stopping itself using the stopSelf() method.<\/li>\n<\/ul>\n<h4>2. Bound Service<\/h4>\n<p>A service is bound only if an application component binds to it using <strong>bindService()<\/strong>. It gives a client-server relation that lets the components interact with the service. The components can send requests to services and get results.<\/p>\n<p>This service runs in the background as long as another application is bound to it. Or it can be unbound according to our requirement by using the<strong> unbindService()<\/strong> method.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/lifecycle-of-android-services.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75236\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/lifecycle-of-android-services.jpg\" alt=\"lifecycle of android services\" width=\"612\" height=\"662\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/lifecycle-of-android-services.jpg 612w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/lifecycle-of-android-services-139x150.jpg 139w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/lifecycle-of-android-services-277x300.jpg 277w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/lifecycle-of-android-services-520x562.jpg 520w\" sizes=\"auto, (max-width: 612px) 100vw, 612px\" \/><\/a><\/p>\n<h4>IntentService()<\/h4>\n<p>There\u2019s an additional service class, that extends Service class, <strong>IntentService<\/strong> Class. It is a base class for services to handle asynchronous requests. It enables running an operation on a single background. It executes long-running programs without affecting any user\u2019s interface interaction. Intent services run and execute in the background and terminate themself as soon as they are executed completely.<\/p>\n<p>Certain important features of Intent are :<\/p>\n<ul>\n<li>It queues up the upcoming request and executes them one by one.<\/li>\n<li>Once the queue is empty it stops itself, without the user\u2019s intervention in its lifecycle.<\/li>\n<li>It does proper thread management by handling the requests on a separate thread.<\/li>\n<\/ul>\n<h3>Methods of Android Services<\/h3>\n<p>The service base class defines certain callback methods to perform operations on applications. When we talk about Android services it becomes quite obvious that these services will do some operations and they\u2019ll be used. The following are a few important methods of Android services :<\/p>\n<ul>\n<li>onStartCommand()<\/li>\n<li>onBind()<\/li>\n<li>onCreate()<\/li>\n<li>onUnbind()<\/li>\n<li>onDestroy()<\/li>\n<li>onRebind()<\/li>\n<\/ul>\n<p>Let us see these methods in detail:<\/p>\n<h4>1. onStartCommand()<\/h4>\n<p>The system calls this method whenever a component, say an <strong>activity<\/strong> requests \u2018start\u2019 to a service, using <strong>startService()<\/strong>.<\/p>\n<p>Once we use this method it\u2019s our duty to stop the service using <strong>stopService()<\/strong> or <strong>stopSelf()<\/strong>.<\/p>\n<h4>2. onBind()<\/h4>\n<p>This is invoked when a component wants to bind with the service by calling<strong> bindService()<\/strong>. In this, we must provide an interface for clients to communicate with the service. For interprocess communication, we use the<strong> IBinder object<\/strong>.<\/p>\n<p>It is a must to implement this method. If in case binding is not required, we should return <strong>null<\/strong> as implementation is mandatory.<\/p>\n<h4>3. onUnbind()<\/h4>\n<p>The system invokes this when all the clients disconnect from the interface published by the service.<\/p>\n<h4>4. onRebind()<\/h4>\n<p>The system calls this method when new clients connect to the service. The system calls it after the <strong>onBind()<\/strong> method.<\/p>\n<h4>5. onCreate()<\/h4>\n<p>This is the first callback method that the system calls when a new component starts the service. We need this method for a one-time set-up.<\/p>\n<h4>6. onDestroy()<\/h4>\n<p>This method is the final clean up call for the system. The system invokes it just before the service destroys. It cleans up resources like <a href=\"https:\/\/developer.android.com\/reference\/java\/lang\/Thread\">threads<\/a>, receivers, registered listeners, etc.<\/p>\n<h3>Implementation of Android Services<\/h3>\n<p>Now we\u2019ll implement services in our <em><strong><a href=\"https:\/\/data-flair.training\/blogs\/installing-android-studio\/\">Android Studio<\/a><\/strong><\/em> with the following code. Along with this, we\u2019ll see the implementation of a few of the callback methods that are required for the service implementation.<\/p>\n<p>1. Now for this, we\u2019ll create a project in our Android Studio and name it. We\u2019re naming it as <strong>Service<\/strong>. Then we\u2019ll write the following code in our <strong>activity_main.xml<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n   android:orientation=\"vertical\" android:layout_width=\"match_parent\"\r\n   android:layout_height=\"match_parent\"&gt;\r\n\r\n   &lt;TextView\r\n       android:id=\"@+id\/textView2\"\r\n       android:layout_width=\"wrap_content\"\r\n       android:layout_height=\"wrap_content\"\r\n       android:layout_centerHorizontal=\"true\"\r\n       android:layout_marginLeft=\"100dp\"\r\n       android:text=\"DataFlair \"\r\n       android:textColor=\"@color\/colorPrimaryDark\"\r\n       android:textSize=\"50dp\" \/&gt;\r\n\r\n   &lt;Button\r\n       android:id=\"@+id\/btnStart\"\r\n       android:layout_width=\"wrap_content\"\r\n       android:layout_height=\"wrap_content\"\r\n       android:layout_marginLeft=\"50dp\"\r\n       android:layout_marginTop=\"50dp\"\r\n       android:onClick=\"startService\"\r\n       android:text=\"Start Service\" \/&gt;\r\n\r\n   &lt;Button\r\n       android:id=\"@+id\/btnstop\"\r\n       android:layout_width=\"wrap_content\"\r\n       android:layout_height=\"wrap_content\"\r\n       android:layout_marginLeft=\"50dp\"\r\n       android:layout_marginTop=\"50dp\"\r\n       android:onClick=\"stopService\"\r\n       android:text=\"Stop Service\" \/&gt;\r\n&lt;\/LinearLayout&gt;<\/pre>\n<p>2. After this, we\u2019ll write the following code in <strong>MainActivity.java<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.DataFlair.DataFlair_Services;\r\n\r\nimport android.content.Intent;\r\nimport android.os.Bundle;\r\nimport android.view.View;\r\nimport androidx.appcompat.app.AppCompatActivity;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n   @Override\r\n   protected void onCreate(Bundle savedInstanceState) {\r\n       super.onCreate(savedInstanceState);\r\n       setContentView(R.layout.activity_main);\r\n   }\r\n\r\n   public void startService(View view) {\r\n       startService(new Intent(this, DataFlairService.class));\r\n   }\r\n\r\n   public void stopService(View view) {\r\n       stopService(new Intent(this, DataFlairService.class));\r\n   }\r\n}<\/pre>\n<p>3. Now open the <strong>Manifest.xml<\/strong> file. Following code is to be written in the Manifest file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\npackage=\"com.DataFlair.DataFlair_Services\"&gt;\r\n\r\n   &lt;application\r\n       android:allowBackup=\"true\"\r\n       android:icon=\"@mipmap\/ic_launcher\"\r\n       android:label=\"@string\/app_name\"\r\n       android:roundIcon=\"@mipmap\/ic_launcher_round\"\r\n       android:supportsRtl=\"true\"\r\n       android:theme=\"@style\/AppTheme\"&gt;\r\n       &lt;activity android:name=\"com.DataFlair.DataFlair_Services.MainActivity\"&gt;\r\n           &lt;intent-filter&gt;\r\n               &lt;action android:name=\"android.intent.action.MAIN\" \/&amp;gt;\r\n               &lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\r\n           &lt;\/intent-filter&gt;\r\n       &lt;\/activity&gt;\r\n       &lt;service android:name=\"com.DataFlair.DataFlair_Services.DataFlairService\" \/&gt;\r\n   &lt;\/application&gt;\r\n&lt;\/manifest&gt;<\/pre>\n<p>4. And finally, we\u2019ll create a file, a java class, and name it. We\u2019re naming it <strong>DataFlairService.java<\/strong>. After this file is created, we\u2019ll write the following code in it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">package com.DataFlair.DataFlair_Services;\r\nimport android.app.Service;\r\nimport android.content.Intent;\r\nimport android.media.MediaPlayer;\r\nimport android.os.IBinder;\r\nimport android.provider.Settings;\r\nimport android.widget.Toast;\r\n\r\npublic class DataFlairService extends Service {\r\n   private MediaPlayer player;\r\n   @Override\r\n   public IBinder onBind(Intent intent) {\r\n       return null;\r\n   }\r\n   @Override\r\n   public void onCreate() {\r\n       Toast.makeText(this, \"Service was Created\", Toast.LENGTH_LONG).show();\r\n   }\r\n   @Override\r\n   public int onStartCommand(Intent intent, int flags, int startId) {\r\n       player = MediaPlayer.create(this, Settings.System.DEFAULT_RINGTONE_URI);\r\n       player.setLooping(true);\r\n       player.start();\r\n       Toast.makeText(this, \"Service Started\", Toast.LENGTH_LONG).show();\r\n       return START_STICKY;\r\n   }\r\n   @Override\r\n   public void onDestroy() {\r\n       super.onDestroy();\r\n       player.stop();\r\n       Toast.makeText(this, \"Service Stopped\", Toast.LENGTH_LONG).show();\r\n   }\r\n}<\/pre>\n<p>5. After we\u2019ve written all the codes respectively, we\u2019ll run our app now. The following would be shown to us as our output:<\/p>\n<p>This is our application wherein we can Start and Stop our service.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Application.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75243 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Application.png\" alt=\"Application - android services\" width=\"225\" height=\"400\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Application.png 225w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Application-84x150.png 84w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Application-169x300.png 169w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>Now we\u2019ve clicked on Start Service, therefore Service is created first.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Created.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75245\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Created.png\" alt=\"Created - android services\" width=\"225\" height=\"400\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Created.png 225w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Created-84x150.png 84w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Created-169x300.png 169w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>After the service is created, it will start executing.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Started.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75246\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Started.png\" alt=\"Started - android services\" width=\"225\" height=\"400\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Started.png 225w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Started-84x150.png 84w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Started-169x300.png 169w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>After that, we can stop our service whenever we like to stop them.<\/p>\n<p>As we can see below, the service has stopped.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Stopped.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75247\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Stopped.png\" alt=\"Stopped - android services\" width=\"225\" height=\"400\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Stopped.png 225w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Stopped-84x150.png 84w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Stopped-169x300.png 169w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<h2>Summary<\/h2>\n<p>Now that we\u2019ve read about Android services, let us see it once again in brief. Android services are the long-running processes that don\u2019t need user interaction. These services run in the background. They work either in <strong>Started mode<\/strong> or <strong>Bound mode<\/strong>. It has also got a few important methods that provide a few important operations.<\/p>\n<p>How was your experience regarding the Android service tutorial? Do share in the comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever thought of a music player, as a service? Yes, the music player is a service. Not sure how? Well, it runs in the background while the user happily uses some other application, isn\u2019t&#46;&#46;&#46;<\/p>\n","protected":false},"author":10,"featured_media":75240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18722],"tags":[21793,21794,21795,21791,21798,21796,21797,21792],"class_list":["post-75209","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-android-bound-service","tag-android-intentservice","tag-android-service-tutorial","tag-android-services","tag-android-services-implementation","tag-android-services-lifecycle","tag-android-services-methods","tag-android-started-service"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Android Service Tutorial - Lifecycle, Methods &amp; Implementation - DataFlair<\/title>\n<meta name=\"description\" content=\"Android Services - Learn about the types of services with their working, services lifecycle, methods and implementation in Android studio.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android Service Tutorial - Lifecycle, Methods &amp; Implementation - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Android Services - Learn about the types of services with their working, services lifecycle, methods and implementation in Android studio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-31T06:47:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T08:25:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Android-Service-Tutorial.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android Service Tutorial - Lifecycle, Methods &amp; Implementation - DataFlair","description":"Android Services - Learn about the types of services with their working, services lifecycle, methods and implementation in Android studio.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Android Service Tutorial - Lifecycle, Methods &amp; Implementation - DataFlair","og_description":"Android Services - Learn about the types of services with their working, services lifecycle, methods and implementation in Android studio.","og_url":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2020-01-31T06:47:16+00:00","article_modified_time":"2021-08-25T08:25:55+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Android-Service-Tutorial.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33"},"headline":"Android Service Tutorial &#8211; Lifecycle, Methods &amp; Implementation","datePublished":"2020-01-31T06:47:16+00:00","dateModified":"2021-08-25T08:25:55+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/"},"wordCount":1110,"commentCount":3,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Android-Service-Tutorial.jpg","keywords":["android bound service","android intentservice","android service tutorial","android services","android services implementation","Android services lifecycle","android services methods","android started service"],"articleSection":["Android Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/android-service-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/","url":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/","name":"Android Service Tutorial - Lifecycle, Methods &amp; Implementation - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Android-Service-Tutorial.jpg","datePublished":"2020-01-31T06:47:16+00:00","dateModified":"2021-08-25T08:25:55+00:00","description":"Android Services - Learn about the types of services with their working, services lifecycle, methods and implementation in Android studio.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/android-service-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Android-Service-Tutorial.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2020\/01\/Android-Service-Tutorial.jpg","width":802,"height":420,"caption":"Android Service Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/android-service-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Android Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/android\/"},{"@type":"ListItem","position":3,"name":"Android Service Tutorial &#8211; Lifecycle, Methods &amp; Implementation"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/a90b082e16aa38d207212d22b0581f33","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/dd6de0d647a0185cd6faf264e4ba860b0d85d08d7070766f9cd41bea5bb0b227?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team is passionate about delivering top-notch tutorials and resources on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. With expertise in the tech industry, we simplify complex topics to help learners excel. Stay updated with our latest insights.","url":"https:\/\/data-flair.training\/blogs\/author\/dfadteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/75209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=75209"}],"version-history":[{"count":9,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/75209\/revisions"}],"predecessor-version":[{"id":76062,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/75209\/revisions\/76062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/75240"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=75209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=75209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=75209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}