Monday, May 3, 2010

[android-developers] My app crashes upon relaunch

Environment:
- Windows XP box
- Eclipse with ADT 9.6
- Test Devices: Droid and Eris

I am putting the finishing touches on a new game -- my first Android
app. The last big problem I am having is as follows.

After launching the app from the home screen, using and exiting,
*relaunching* the app from the home screen generates an exception.
Looking at LogCat shows the following error: "ERROR/dalvikvm-
heap(25501): 1728000-byte external allocation too large for this
process." Pressing [Force Close] closes the app. The 3rd attempt to
run is successful.

What I Know:

- The app properly handles the [HOME] button, i.e. disappears and
reappears at the user's discretion.

- The app has two activities: Intro and Game

- The Intro activity has MAIN and LAUNCHER attributes in manifest. It
does very few allocations but does have a couple screen-sized bitmaps
that are displayed. When the user is ready to move to the Game
activity, the Game activity is started and the Intro activity is
finished (onDestroy() is called).

- The Game activity has many allocations of all sizes. I know I am
cruising near the max amount of allocations because I am constantly
refactoring the app to find ways to creatively stay within memory
limits. The Game activity has a thread that runs for the life of the
activity. When the user ends the app with the BACK key the app starts
its clean-up. The thread appears to be properly finishing as does the
activity (onDestroy() is called). The app's onTerminate() method is
never called (based on my hours of searching for answers, it's seems
this is okay).

- I was having memory limit problems a couple weeks ago and that was
the reason I divided a single activity into two activities. I was
surprised that this, alone, did not solve my problem. Within the
Intro Activity (which, as I stated, appears to be finishing properly)
I had explicitly set the only view's background to null since it has a
big bitmap. This worked but was a surprising solution since I thought
the View object, etc. would all be GC'ed when the activity finished,
so I am uneasy about it as a long-term solution.

- At this point I am suspicious of two things: memory leaks and
improper management of app/activity life cycle.

- Memory Leaks: I have done pretty deep memory leak debugging in the
past in the C++/Windows world. In the Android/Eclipse world, I am a
novice. I have gotten as far as getting the Allocation Tracker to
show up in Eclipse. I have not been successful in getting it to
display allocations for the app.

Improper App/Activity Life Cycle: I *think* I'm doing all the right
things but obviously I am not. My assumption originally was the the
app's onTerminate() was where I should clean up global items. Since
it's not being called, I moved that clean-up to Game activity. I have
tried a variety of Activity attributes (such as "Finish on Task
Launch") with no success. Admittedly, I am trying these but not with
confidence in my understanding of what the all, exactly, mean.

- The location of the memory allocation is noted in the code snippet
below. What's odd is that app's onCreate() is only called during the
first launch, not the 2nd.

Thank you for your help.

Tom

====== Intro Activity's onCreate() =========

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.i("Tom", "IntroActivity.onCreate()");

setContentView(R.layout.intro); <------------ Causes
Crash

Log.i("Tom", "m_app = " + m_app);
m_app = BasketballApp.GetInstance();
Log.i("Tom", "m_app = " + m_app);
:
}

====== Custom LogCat Dump =========

-- 1st Launch
05-03 16:36:46.483: INFO/Tom(25670): app.onCreate()
05-03 16:36:46.491: INFO/Tom(25670): - Looks like App is starting
fresh
05-03 16:36:46.507: INFO/Tom(25670): IntroActivity.onCreate()
05-03 16:36:47.202: INFO/Tom(25670): m_app = null
05-03 16:36:47.202: INFO/Tom(25670): m_app =
LizardTap.Basketball1.BasketballApp@447bf8a8
05-03 16:36:59.124: INFO/Tom(25670): Activity: onCreate()
05-03 16:36:59.460: INFO/Tom(25670): GameView $
05-03 16:36:59.460: INFO/Tom(25670): BasketballThread $()
05-03 16:37:00.710: INFO/Tom(25670): Activity: onStart()
05-03 16:37:00.710: INFO/Tom(25670): Activity: onResume()
05-03 16:37:00.882: INFO/Tom(25670): IntroActivity.onDestroy()
05-03 16:37:09.616: INFO/Tom(25670): surfaceCreated()
05-03 16:37:09.616: INFO/Tom(25670): startGameThread()
05-03 16:37:09.616: INFO/Tom(25670): freezeGameThread()
05-03 16:37:09.616: INFO/Tom(25670): setSurfaceSize()
05-03 16:37:09.655: INFO/Tom(25670): thread.run {start}
05-03 16:37:09.710: INFO/Tom(25670): _setSurfaceSize() end
05-03 16:37:20.147: INFO/Tom(25670): Activity: onPause()
05-03 16:37:20.303: INFO/Tom(25670): surfaceDestroyed()
05-03 16:37:20.311: INFO/Tom(25670): freezeGameThread()
05-03 16:37:20.585: INFO/Tom(25670): Activity: onStop()
05-03 16:37:20.585: INFO/Tom(25670): Activity: onDestroy()
05-03 16:37:20.593: INFO/Tom(25670): stopGameThread()
05-03 16:37:20.616: INFO/Tom(25670): thread.run {end}
-- 2nd Launch
05-03 16:37:22.522: INFO/Tom(25670): IntroActivity.onCreate() <----
notice not preceded by app.onCreate()

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate