Skip to main content

Thread vs Service in Android - ABNHive

The thread is part of your program functionality that can run in parallel with the main application execution process (or thread). It runs withing a process. The process may contain only, and that’s rare one thread and mostly contains multiple threads. Threads share the same resources and memory. Creating new thread need very less work that creating a new process.


Use a Thread when

  • The app is required to be visible when the operation occurs.
  • background operation is relatively short running (less than a minute or two)
  • the activity/screen/app is highly coupled with the background operation, the user usually 'waits' for this operation to finish before doing anything else in the app. Using a thread in these cases leads to cleaner, more readable & maintainable code. That being said its possible to use a Service( or IntentService).

Use a Service when

  • The app could be invisible when the operation occurs (Features like Foreground service could help with operations being interrupted)
  • The user is not required to 'wait' for the operation to finish to do other things in the app.
  • The app is visible and the operation is independent of the app/screen context.


Comments

Popular posts from this blog

Android Application Components Activities, Services, Broadcast Recievers, Content Providers - ABNHive

Application components are the essential building blocks of Android app development.  Each component is an entry point through which the system or a user can enter your app. There are 4 types of components in android Activities Services Broadcast receivers Content providers Let's dive into the deep.  Activities This is a component that represents a single screen with a user interface or simply an entry point for interacting with the user. Example, an email app might have one activity that shows a list of new emails. Activities work together to form a cohesive user experience in the app. For example, clicking a button on the first screen might replace that screen with another screen containing other widgets, a web page, a movie, or text information. Activities are typically created by subclassing (extending) the Android class Activity.  click here   to know more about Activity. Services This runs in the background ...

Talk about Ingredients before cooking in Android, the complete android tools - ABN Hive

We should know about the ingredients before cooking. Besides, we need to know about tools before developing android applications. Let's talk about it. Android Studio  This is the IDE (Integrated Development Environment) to make Android Applications. Android Studio provides the fastest tools for building apps on every type of Android device. It contains tools for development, debugging, testing, and performance that make it faster and easier to develop apps like these, Visual Layout Editor APK Analyzer Fast Emulator Intelligent Code Editor Flexible build System System requirements Windows Microsoft® Windows® 7/8/10 (32- or 64-bit) 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator 2 GB of available disk space minimum, 4 GB Recommended (500 MB for IDE + 1.5 GB for Android SDK and emulator system image) 1280 x 800 minimum screen resolution Mac Mac® OS X® 10.10 (Yosemite) or higher, up to 10.13 (macOS High Sierra) 3 ...