---
title: "Start a service in android"  
description: "Start a service in android"  
author: "Anonymous User"  
published: 2015-08-05  
updated: 2015-08-06  
canonical: https://www.mindstick.com/forum/33397/start-a-service-in-android  
category: "android"  
tags: ["android", "android troubleshooting"]  
reading_time: 2 minutes  

---

# Start a service in android

Suppose that you are [starting](https://www.mindstick.com/blog/12024/things-you-need-to-know-when-starting-your-own-business) a [service](https://www.mindstick.com/articles/105963/online-thesis-writing-service-for-college-kids-with-disabilities) in an [Activity](https://www.mindstick.com/forum/12894/how-to-force-recreation-of-activity-fragment-on-restore) as follows:

```
Intent service = new Intent(context, MyService.class);             startService(service);
```

where **MyService** accesses a [remote](https://www.mindstick.com/articles/85431/remote-employee-training-tips-tricks) [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) via an [Internet connection](https://www.mindstick.com/blog/299301/how-to-test-your-internet-connection-s-quality-over-time).\
If the Activity is showing an [animation](https://www.mindstick.com/articles/13040/seven-helpful-tips-to-start-and-grow-an-animation-video-company) that indicates some kind of [progress](https://yourviews.mindstick.com/view/284/devotees-arrived-in-prayagraj-while-work-is-still-in-progress), what issue might you encounter and how could you address it?

## Replies

### Reply by Anonymous User

Responses from a remote service via the [Internet](https://www.mindstick.com/articles/44650/what-should-you-do-during-an-internet-outage) can often take some time, either due to networking latencies, or load on the remote server, or the amount of time it takes for the remote service to process and respond to the request.\
As a result, if such a delay occurs, the animation in the activity (and even worse, the entire UI thread) could be blocked and could appear to the user to be “frozen” while the client waits for a response from the service. This is because the service is started on the main application thread (or UI thread) in the Activity.\
The problem can (and should) be avoided by relegating any such remote requests to a background thread or, when feasible, using an an asynchronous response mechanism.\
Note well: Accessing the network from the UI thread throws a runtime exception in newer Android versions which causes the app to crash.


---

Original Source: https://www.mindstick.com/forum/33397/start-a-service-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
