You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/html/guide/practices/design/responsiveness.jd
+33-27Lines changed: 33 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -1,45 +1,49 @@
1
1
page.title=Designing for Responsiveness
2
2
@jd:body
3
3
4
-
<p>It's possible to write code that wins every performance test in the world, but still sends users in a fiery rage when they try to use the application. These are the applications that aren't <em>responsive</em> enough — the ones that feel
5
-
sluggish, hang or freeze for significant periods, or take too long to process
6
-
input. </p>
7
-
8
-
<p>In Android, the system guards against applications that are insufficiently responsive for a period of time by displaying a dialog to the user, called the Application Not Responding (ANR) dialog. The user can choose to let the application continue, but the user won't appreciate having to act on this dialog every time he or she uses your application. So it's important to design responsiveness into your application, so that the system never has cause to display an ANR to the user. </p>
4
+
<div class="figure">
5
+
<img src="{@docRoot}images/anr.png" alt="Screenshot of ANR dialog box" width="240" height="320"/>
6
+
<p><strong>Figure 1.</strong> An ANR dialog displayed to the user.</p>
7
+
</div>
9
8
10
-
<p>Generally, the system displays an ANR if an application cannot respond to user input. For example, if an application blocks on some I/O operation (frequently a network access), then the main application thread won't be able to process incoming user input events. After a time, the system concludes that the application has hung, and displays the ANR to give the user the option to kill it.
9
+
<p>It's possible to write code that wins every performance test in the world,
10
+
but still sends users in a fiery rage when they try to use the application.
11
+
These are the applications that aren't <em>responsive</em> enough — the
12
+
ones that feel sluggish, hang or freeze for significant periods, or take too
13
+
long to process input. </p>
14
+
15
+
<p>In Android, the system guards against applications that are insufficiently
16
+
responsive for a period of time by displaying a dialog to the user, called the
17
+
Application Not Responding (ANR) dialog, shown at right in Figure 1. The user
18
+
can choose to let the application continue, but the user won't appreciate having
19
+
to act on this dialog every time he or she uses your application. It's critical
20
+
to design responsiveness into your application, so that the system never has
21
+
cause to display an ANR dialog to the user. </p>
22
+
23
+
<p>Generally, the system displays an ANR if an application cannot respond to
24
+
user input. For example, if an application blocks on some I/O operation
25
+
(frequently a network access), then the main application thread won't be able to
26
+
process incoming user input events. After a time, the system concludes that the
27
+
application is frozen, and displays the ANR to give the user the option to kill
28
+
it. </p>
11
29
12
30
<p>Similarly, if your application spends too much time building an elaborate in-memory
13
31
structure, or perhaps computing the next move in a game, the system will
14
32
conclude that your application has hung. It's always important to make
15
33
sure these computations are efficient using the techniques above, but even the
16
34
most efficient code still takes time to run.</p>
17
35
18
-
<p>In both of these cases, the fix is usually to create a child thread, and do
36
+
<p>In both of these cases, the recommended approach is to create a child thread and do
19
37
most of your work there. This keeps the main thread (which drives the user
20
-
interface event loop) running, and prevents the system from concluding your code
38
+
interface event loop) running and prevents the system from concluding that your code
21
39
has frozen. Since such threading usually is accomplished at the class
22
40
level, you can think of responsiveness as a <em>class</em> problem. (Compare
23
41
this with basic performance, which was described above as a <em>method</em>-level
24
42
concern.)</p>
25
43
26
-
<div class="sidebox-wrapper">
27
-
<div class="sidebox">
28
-
<img src="{@docRoot}images/anr.png" width="240" height="320" alt="Screenshot of ANR dialog box">
29
-
<p style="margin-top:.5em;padding:.5em;">An ANR dialog displayed to the user.</p>
30
-
</div>
31
-
</div>
32
-
33
-
<p>This document discusses how the Android system determines whether an application is
34
-
not responding and provides guidelines for
35
-
ensuring that your application is responsive. </p>
0 commit comments