Each app runs in its own process and contains one or more activities.
The Android run time manages these processes and decides which app to kill if it needs resources.
An app’s priority helps determine if the run time will kill it and its running activities.
The app’s priority is influenced by its highest priority activity.
If the Android’s memory manager needs to free up memory, it looks at the activity stack to determine the priority of the activities and which ones can be closed.
The download manager was introduced in Android 2.3 (API level 9).
It’s a System Service that optimises the handling of long-running downloads in the background.
The download manager handles HTTP connections, monitors connectivity changes, reboots, and ensures each download completes successfully
Its good practice to use the download manager for most downloads, especially if the download continues between user sessions or if success is important.
All Android components (like activities and services) start on the main thread. This is the thread that the user interacts with.
You need to keep this thread clear so that the app does not hang. It’s a good idea to put all time-consuming processes on a separate thread.
Put file operations, network lookups, database interaction, etc. on a background thread.
You should do time consuming work, like downloading files, on a separate thread.
This will free up the main thread so your user can carry on using the app.
IntentServices are the preferred way for doing long running background operations.
You can request an IntentService from any of your fragments or activities. The requests are queued and handled one-after-the-other. The IntentService stops once all the requests have been handled.
Sometimes, you may need to get data from another activity. That activity could be in your app or in another app.
You could use startActivityForResult() to get that data for you.
You may want to pass data from one activity to another.
You could put the data in a central point and then access it from anywhere.
Here are some of the ways to do that:
Well, it's the next best thing since sliced bread! This is what they can do for you:
You use a content provider to make your database accessible to other apps.
You use a content resolver to access a database in another app.
We covered building our provider class in Part 1. Now in Part 2, we’ll see how we use the provider to access the database.
We will be accessing the database from within the app that created it but we will still use a content resolver to do so.
This is part 1 of creating our custom content provider. This is where we build our ContentProvider class.
In part 2, we'll show how we use the provider within the same app to access the database.