From 17de2cce1ab51e1920a24826cd1f2eba7e4c9257 Mon Sep 17 00:00:00 2001
From: Adarsh Fernando
- Background processes can be memory and battery intensive. For example,
- Implicit broadcasts frequently start background apps that have registered to
- listen for them. This can have a substantial impact on device performance and
- user experience.
+ Background processes can be memory- and battery-intensive. For example, an
+ implicit broadcast may start many background processes that have registered
+ to listen for it, even if those processes may not do much work. This can have
+ a substantial impact on both device performance and user experience.
- To alleviate this issue, Android N applies the following
+ To alleviate this issue, the N Developer Preview applies the following
restrictions:
-
@@ -79,12 +76,11 @@ page.keywords="android N", "implicit broadcasts", "job scheduler"
these implicit broadcasts. For example, {@link android.app.job.JobScheduler}
and
- GcmNetworkManager provide robust mechanisms to schedule network
+ {@code GcmNetworkManager} provide robust mechanisms to schedule network
operations when specified conditions, such as a connection to an unmetered
- network, are met. You can also use {@link android.app.job.JobScheduler} to
- react to changes to content providers. {@link android.app.job.JobInfo}
- objects, built by the {@link android.app.job.JobInfo.Builder JobInfo.Builder}
- class, encapsulate the parameters that {@link android.app.job.JobScheduler}
+ network, are met. You can now also use {@link android.app.job.JobScheduler}
+ to react to changes to content providers. {@link android.app.job.JobInfo}
+ objects encapsulate the parameters that {@link android.app.job.JobScheduler}
uses to schedule your job. When the conditions of the job are met, the system
executes this job on your app's {@link android.app.job.JobService}.
- Apps targeting Android N do not receive {@link - android.net.ConnectivityManager#CONNECTIVITY_ACTION} broadcasts, even if they - register to receive them in their manifest. This could pose a problem for - apps that want to listen for network changes or perform bulk network - activities when the device connects to an unmetered network. Several - solutions to get around this restriction already exist in the Android - framework, but choosing the right one depends on what you want your app to - accomplish. + Apps targeting the N Developer Preview do not receive {@link + android.net.ConnectivityManager#CONNECTIVITY_ACTION} broadcasts if they + register to receive them in their manifest, and processes that depend on this + broadcast will not start. This could pose a problem for apps that want + to listen for network changes or perform bulk network activities when the + device connects to an unmetered network. Several solutions to get around this + restriction already exist in the Android framework, but choosing the right + one depends on what you want your app to accomplish.
Note: A {@link android.content.BroadcastReceiver} registered with {@link android.content.Context#registerReceiver Context.registerReceiver()} - continues to receive these broadcasts on the app’s main activity thread. + continues to receive these broadcasts while the app is in the foreground.
@@ -138,7 +134,7 @@ public static void scheduleJob(Context context) {
(JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo job = new JobInfo.Builder(
MY_BACKGROUND_JOB,
- new ComponentName(context, JobService.class))
+ new ComponentName(context, MyJobService.class))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
.setRequiresCharging(true)
.build();
@@ -155,10 +151,10 @@ public static void scheduleJob(Context context) {
-Applications that use GMSCore services, and target Android 5.0 (API level 21)
-or lower, should use
-GcmNetworkManager and specify {@code Task.NETWORK_STATE_UNMETERED}.
+ Applications that use GMSCore services, and target Android 5.0 (API level 21)
+ or lower, can use
+ {@code GcmNetworkManager} and specify {@code Task.NETWORK_STATE_UNMETERED}.
@@ -170,7 +166,7 @@ GcmNetworkManager and specify {@code Task.NETWORK_STATE_UNMETERED}.
CONNECTIVITY_CHANGE} with a registered {@link
android.content.BroadcastReceiver}. However, the {@link
android.net.ConnectivityManager} API provides a more robust method to request
- a callback during specified network conditions.
+ a callback only when specified network conditions are met.
@@ -193,44 +189,17 @@ GcmNetworkManager and specify {@code Task.NETWORK_STATE_UNMETERED}.
unregisterNetworkCallback()}.
-
- Persistent Monitoring of Network Connectivity
-
-
-
- The {@link android.net.ConnectivityManager} API also provides a method to
- persistently monitor network connectivity. Due to its impact on performance,
- however, it should be used with caution.
-
-
-
- An app may use {@link
- android.net.ConnectivityManager#registerNetworkCallback(android.net.NetworkRequest,
- android.app.PendingIntent) registerNetworkCallback()} to register a {@link
- android.app.PendingIntent} rather than a {@link
- android.net.ConnectivityManager.NetworkCallback}. The request may outlive the
- calling app and require it to start up in order to process a callback.
-
-
-
- Before considering this option, think twice about whether this solution is
- actually necessary, and consider the impact to performance and user
- experience when doing so. Only apps that have a real need to start up on a
- network change should implement this solution. Otherwise, every effort should
- be taken to implement the alternatives.
-
-
Restrictions on NEW_PICTURE and NEW_VIDEO
- In Android N, apps are not able to send or receive {@code
+ In the N Developer Preview, apps are not able to send or receive {@code
NEW_PICTURE} or {@code NEW_VIDEO} broadcasts. This restriction helps
alleviate the performance and user experience impacts when several apps must
- wake up in order to process them. Android N extends {@link
- android.app.job.JobInfo} and {@link android.app.job.JobParameters} to provide
- an alternative solution.
+ wake up in order to process a new image or video. The N Developer Preview
+ extends {@link android.app.job.JobInfo} and {@link
+ android.app.job.JobParameters} to provide an alternative solution.
@@ -238,7 +207,7 @@ GcmNetworkManager and specify {@code Task.NETWORK_STATE_UNMETERED}.
- To help trigger jobs on content URI changes, Android N extends
+ To trigger jobs on content URI changes, the N Developer Preview extends
the {@link android.app.job.JobInfo} API with the following methods:
@@ -257,8 +226,8 @@ GcmNetworkManager and specify {@code Task.NETWORK_STATE_UNMETERED}.
- Android N also extends {@link android.app.job.JobParameters} to + The N Developer Preview also extends {@link android.app.job.JobParameters} to allow your app to receive useful information about what content authorities and URIs triggered the job:
@@ -384,17 +353,18 @@ public boolean onStartJob(JobParameters params) {Optimizing your apps to run on low-memory devices, or in low-memory - conditions, can improve performance and user experience. Eliminating the use - of implicit broadcasts and background services is a great way to make sure - your app runs well on such devices. Although Android N takes - steps to limit the use of certain implicit broadcasts, consider optimizing - your app to run without the use of implicit broadcasts and background - services, entirely.
+ conditions, can improve performance and user experience. Removing + dependencies on background services and statically-registered implicit + broadcast receivers can help your app run better on such devices. Although + the N Developer Preview takes steps to reduce some of these issues, it is + recommended that you optimize your app to run without the use of these + background processes entirely. +- To help you test how your app behaves without those background processes, - Android N introduces some additional Android Debug Bridge (ADB) commands: + The N Developer Preview introduces some additional Android Debug Bridge (ADB) commands that + you can use to test app behavior with those background processes disabled:
- The Android framework is constantly evolving to help apps run great on a wide - variety of devices. To learn more and join the discussion, read this blog post! -
+ \ No newline at end of file