create account

Services | Android App Development | Lecture#57 | Hive Learners by faisalamin

View this thread on: hive.blogpeakd.comecency.com
· @faisalamin ·
$21.91
Services | Android App Development | Lecture#57 | Hive Learners
<center><h2>𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼</h2></center>
<div class="text-justify">

Hello dear Hive Learner, In the previous lecture we learn how to update, and delete data from the Firestore. Today we will learn how the services work in Android. Services are the background task that will work behind the scenes until we manually stop them. Most of the time we use the Services for the Android Notification. Let's get started.

![](https://images.ecency.com/DQmRk1tqy6x6T7NQSW47RNfFJDkfqgKYzX9DtMt9DNDRqUp/multi_purpose_5_.png)


## [GitHub Link](https://github.com/faisalamin9696/HiveLearners2)

Use this GitHub project to clone into your directory. The following lecture will update it so you will never miss the latest code. Happy Coding!

## What Should I Learn

- What are the services
- How to implement service in your project

## Assignment

- Implement service in your project

## Procedure

To implement the service we need to create an empty java class and extend it with the Service. I will create a java class ```MyService.java``` and extend it with the Service.

![](https://images.ecency.com/DQmZyBXywFo7qbjyf33EouNSnwQg7xpVUua8Kf6kQqwunbX/image.png)

Now we need to override these methods.

```
public class MyService extends Service {


    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        return super.onUnbind(intent);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }



}

```
![](https://images.ecency.com/DQmQdxg8EFxwn9h2ZQ77bvtyG8pGif8qEHzSz1LXaytWzpN/image.png)

We can also show a Toast message on Service start and on Service Stop. We also need to declare this service in the Android Manifest file.

![](https://images.ecency.com/DQmWdANa4Ri1ogDuWhoETRpo5Vi8VfCQJqqrjK7D4ARgzoJ/image.png)


Now we can start a stop this service. I am using the Welcom_Activity tabs to start and stop the service.

```
switch (position) {
                    case 0:
                        fragment = new Blogs_Fragment();
                        startService(new Intent(getBaseContext(), MyService.class));

                        break;
                    case 1:
                        fragment = new Transfers_Fragment();
                        stopService(new Intent(getBaseContext(), MyService.class));

                        break;
```

![](https://images.ecency.com/DQmNy73ctnDuqQNDoXfpP1EHVuDQ8osoWBKYvMTMHX1Nq4s/image.png)

Let's run and check if the service is working or not. We need to change the tab to stop and start the service. We can implement it n the button press or in the activity start or destroy.</div>

![](https://images.ecency.com/DQmXWc3X3Pf2agPHYZ8t9dWHrEFXqfM5ueiXpJ7DQqW8srG/image.png)

<center>
![hl_divider.png](https://images.ecency.com/DQmabQycJhW8DT8a634z3wQaVXvPZ5KMii2LYbaWZ3PsaRy/hl_divider.png)

<h2>Thank You</h2>

![hl_footer_banner.png](https://images.ecency.com/DQmZ4HF3hjV4HwJXuw8vRJ6B6CiMC3kUkkoihjtm7z2Gii7/hl_footer_banner.png)
<div class="pull-left"><a href="https://discord.gg/7Bzqv4qUMT">
<img src="https://cdn.steemitimages.com/DQmXd6PwGUHRgSDkWtwKfDvdFpaLHXvXBdK7wnYZeqe1GUa/discord_animation_logo.gif"/></a>
</center>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 224 others
properties (23)
authorfaisalamin
permlinkservices-or-android-app-development
categoryhive-153850
json_metadata"{"links": ["https://github.com/faisalamin9696/HiveLearners2", "https://discord.gg/7Bzqv4qUMT"], "image": ["https://images.ecency.com/DQmRk1tqy6x6T7NQSW47RNfFJDkfqgKYzX9DtMt9DNDRqUp/multi_purpose_5_.png", "https://images.ecency.com/DQmZyBXywFo7qbjyf33EouNSnwQg7xpVUua8Kf6kQqwunbX/image.png", "https://images.ecency.com/DQmQdxg8EFxwn9h2ZQ77bvtyG8pGif8qEHzSz1LXaytWzpN/image.png", "https://images.ecency.com/DQmWdANa4Ri1ogDuWhoETRpo5Vi8VfCQJqqrjK7D4ARgzoJ/image.png", "https://images.ecency.com/DQmNy73ctnDuqQNDoXfpP1EHVuDQ8osoWBKYvMTMHX1Nq4s/image.png", "https://images.ecency.com/DQmXWc3X3Pf2agPHYZ8t9dWHrEFXqfM5ueiXpJ7DQqW8srG/image.png", "https://images.ecency.com/DQmabQycJhW8DT8a634z3wQaVXvPZ5KMii2LYbaWZ3PsaRy/hl_divider.png", "https://images.ecency.com/DQmZ4HF3hjV4HwJXuw8vRJ6B6CiMC3kUkkoihjtm7z2Gii7/hl_footer_banner.png", "https://cdn.steemitimages.com/DQmXd6PwGUHRgSDkWtwKfDvdFpaLHXvXBdK7wnYZeqe1GUa/discord_animation_logo.gif"], "thumbnails": ["https://images.ecency.com/DQmRk1tqy6x6T7NQSW47RNfFJDkfqgKYzX9DtMt9DNDRqUp/multi_purpose_5_.png", "https://images.ecency.com/DQmZyBXywFo7qbjyf33EouNSnwQg7xpVUua8Kf6kQqwunbX/image.png", "https://images.ecency.com/DQmQdxg8EFxwn9h2ZQ77bvtyG8pGif8qEHzSz1LXaytWzpN/image.png", "https://images.ecency.com/DQmWdANa4Ri1ogDuWhoETRpo5Vi8VfCQJqqrjK7D4ARgzoJ/image.png", "https://images.ecency.com/DQmNy73ctnDuqQNDoXfpP1EHVuDQ8osoWBKYvMTMHX1Nq4s/image.png", "https://images.ecency.com/DQmXWc3X3Pf2agPHYZ8t9dWHrEFXqfM5ueiXpJ7DQqW8srG/image.png", "https://images.ecency.com/DQmabQycJhW8DT8a634z3wQaVXvPZ5KMii2LYbaWZ3PsaRy/hl_divider.png", "https://images.ecency.com/DQmZ4HF3hjV4HwJXuw8vRJ6B6CiMC3kUkkoihjtm7z2Gii7/hl_footer_banner.png", "https://cdn.steemitimages.com/DQmXd6PwGUHRgSDkWtwKfDvdFpaLHXvXBdK7wnYZeqe1GUa/discord_animation_logo.gif"], "users": ["Override", "Override", "Override", "Override", "Nullable", "Override"], "tags": ["hive-153850", "stem", "pakistan", "android", "firebase", "education", "development", "services"], "description": "", "app": "ecency/3.0.26-vision", "format": "markdown+html"}"
created2022-08-27 14:30:24
last_update2022-08-27 14:30:24
depth0
children3
last_payout2022-09-03 14:30:24
cashout_time1969-12-31 23:59:59
total_payout_value10.992 HBD
curator_payout_value10.915 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,444
author_reputation104,701,778,605,493
root_title"Services | Android App Development | Lecture#57 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,082,415
net_rshares31,156,932,934,471
author_curate_reward""
vote details (288)
@ecency ·
**Yay!** 🤗<br>Your content has been **boosted with Ecency Points**, by @faisalamin. <br>Use Ecency daily to boost your growth on platform! <br><br><b>Support Ecency</b><br>[Vote for new Proposal](https://hivesigner.com/sign/update-proposal-votes?proposal_ids=%5B197%5D&approve=true)<br>[Delegate HP and earn more](https://ecency.com/hive-125125/@ecency/daily-100-curation-rewards)
properties (22)
authorecency
permlinkre-2022827t15491236z
categoryhive-153850
json_metadata{"tags":["ecency"],"app":"ecency/3.0.20-welcome","format":"markdown+html"}
created2022-08-27 15:49:12
last_update2022-08-27 15:49:12
depth1
children0
last_payout2022-09-03 15:49:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length380
author_reputation628,550,208,526,238
root_title"Services | Android App Development | Lecture#57 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,084,278
net_rshares0
@stemsocial ·
re-faisalamin-services-or-android-app-development-20220828t005021700z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-faisalamin-services-or-android-app-development-20220828t005021700z
categoryhive-153850
json_metadata{"app":"STEMsocial"}
created2022-08-28 00:50:21
last_update2022-08-28 00:50:21
depth1
children0
last_payout2022-09-04 00:50:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,928,211,284,618
root_title"Services | Android App Development | Lecture#57 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,096,844
net_rshares0
@xyz.store ·
Hi @faisalamin, 

Do you know you could have used the tag #diy to earn BUIDL tokens.

In case you are not aware, read this [post](https://peakd.com/hive-167922/@invest.country/build-it-the-hidden-treasure-that-you-need-to-know) to know the kinds of content you could post using #diy tag.

Because most people are not aware of the potential of BUIDL token, it can be bought at very cheap price now.

Posted using [HiveLIST](https://www.hivelist.org/@xyz.store/re-faisalamin-l7g4kt2v)
properties (22)
authorxyz.store
permlinkre-faisalamin-l7g4kt2v
categoryhive-153850
json_metadata{"tags":["hivelist","diy"],"format":"markdown","canonical_url":"https://www.hivelist.org/@xyz.store/re-faisalamin-l7g4kt2v","app":"hivelist/1.1.0"}
created2022-08-30 11:47:51
last_update2022-08-30 11:47:51
depth1
children0
last_payout2022-09-06 11:47:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length482
author_reputation679,821,285,816
root_title"Services | Android App Development | Lecture#57 | Hive Learners"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id116,165,772
net_rshares0