Skip to content

Commit 1c88e2f

Browse files
committed
Shrink the animation to prevent OOM
1 parent a83cae4 commit 1c88e2f

File tree

7 files changed

+17
-11
lines changed

7 files changed

+17
-11
lines changed
-4.28 KB
Loading
-4.24 KB
Loading
-4.22 KB
Loading
-4.23 KB
Loading
-4.27 KB
Loading

06/AsyncTaskDemo/res/layout/asyncdemo.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,10 @@
2222
android:textColor="@android:color/black"
2323
/>
2424

25+
<FrameLayout
26+
android:id="@+id/dots"
27+
android:layout_width="fill_parent"
28+
android:layout_height="wrap_content"
29+
/>
30+
2531
</LinearLayout>

06/AsyncTaskDemo/src/com/oreilly/demo/android/ch06/AsyncTaskDemo.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ public class AsyncTaskDemo extends Activity {
2020
private final class AsyncInitGame
2121
extends AsyncTask<String, Void, String>
2222
{
23-
private final View root;
23+
private final View dots;
2424
private final Game game;
2525
private final TextView message;
2626
private final Drawable bg;
2727

2828
public AsyncInitGame(
29-
View root,
29+
View dots,
3030
Drawable bg,
3131
Game game,
3232
TextView msg)
3333
{
34-
this.root = root;
34+
this.dots = dots;
3535
this.bg = bg;
3636
this.game = game;
3737
this.message = msg;
@@ -40,16 +40,16 @@ public AsyncInitGame(
4040
// runs on the UI thread
4141
@Override protected void onPreExecute() {
4242
if (0 >= mInFlight++) {
43-
root.setBackgroundResource(R.anim.dots);
44-
((AnimationDrawable) root.getBackground()).start();
43+
dots.setBackgroundResource(R.anim.dots);
44+
((AnimationDrawable) dots.getBackground()).start();
4545
}
4646
}
4747

4848
// runs on the UI thread
4949
@Override protected void onPostExecute(String msg) {
5050
if (0 >= --mInFlight) {
51-
((AnimationDrawable) root.getBackground()).stop();
52-
root.setBackgroundDrawable(bg);
51+
((AnimationDrawable) dots.getBackground()).stop();
52+
dots.setBackgroundDrawable(bg);
5353
}
5454

5555
message.setText(msg);
@@ -71,9 +71,9 @@ public void onCreate(Bundle state) {
7171
super.onCreate(state);
7272

7373
setContentView(R.layout.asyncdemo);
74-
75-
final View root = findViewById(R.id.root);
76-
final Drawable bg = root.getBackground();
74+
75+
final View dots = findViewById(R.id.dots);
76+
final Drawable bg = dots.getBackground();
7777

7878
final TextView msg = ((TextView) findViewById(R.id.msg));
7979

@@ -84,7 +84,7 @@ public void onCreate(Bundle state) {
8484
@Override public void onClick(View v) {
8585
//initGame(
8686
new AsyncInitGame(
87-
root,
87+
dots,
8888
bg,
8989
game,
9090
//msg,

0 commit comments

Comments
 (0)