2

I have a very hard to pin down problem.

When I install my app from the marketplace, I sometimes see the following behavior:

  1. Navigating away from the app calls onStop, as expected
  2. Returning to the app calls onCreate for the main activity, instead of just onRestart/onResume

onCreate will keep getting called every time a user leaves/returns to the app, no matter what. Obviously, this causes big issues in terms of state, etc.

Sometimes rebooting the phone fixes this problem, sometimes not. Installing from .adb prevents this behavior.

Log from behaving app, on icon touch (while running already):

2-10 18:56:33.855: INFO/ActivityManager(1482): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.sidekickApp/.Main } from pid 1604
02-10 18:56:33.855: VERBOSE/HtcAppUsageStats(1482): (launch app, package): (Sidekick App, com.sidekickApp)
02-10 18:56:33.865: DEBUG/PhoneWindow(1604): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@40547888 has no id.
02-10 18:56:33.865: DEBUG/Background traffic light(1604): traffic light: GREEN, mBackgroundTrafficLight = false
02-10 18:56:33.895: VERBOSE/Main(2648): Debug: onRestart()
02-10 18:56:33.895: DEBUG/Main(2648): Debug: onResume()

Log from messed up app:

02-10 18:39:35.813: INFO/ActivityManager(1477): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.sidekickApp/.Main bnds=[360,586][477,704] } from pid 1583
02-10 18:39:35.843: VERBOSE/HtcAppUsageStats(1477): (launch app, package): (Sidekick App, com.sidekickApp)
02-10 18:39:35.873: DEBUG/Background traffic light(1583): traffic light: GREEN, mBackgroundTrafficLight = true
02-10 18:39:35.903: VERBOSE/Main(7364): Debug: onCreate()

I am desperate here. Any ideas?

TomBomb
  • 3,236
  • 5
  • 31
  • 40
  • I think it is unpredicatable and not guaranteed. IF application acitivty is not in stack, oncreate will be called otherwise onResume will be called. This is lifecycle. – kosa Feb 11 '12 at 06:40

3 Answers3

2

if onStop() is being called, there is nothing to onResume. It is only called after onPause. And onRestart is only called if you code for it. See http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

Bill Gary
  • 2,987
  • 2
  • 15
  • 19
  • Hmm..when I hit the "Home" button, my log shows onPause followed by onStop. When I hit the app icon, my log shows onRestart followed by onResume. – TomBomb Feb 11 '12 at 06:50
  • That's the way it should be, is the code in your onRestart() now running? – Bill Gary Feb 11 '12 at 07:00
  • Right, that's the way it should be..my issue is that the app can get into a state when hitting the icon triggers onCreate as opposed to onRestart. Nothing else is hogging memory on the phone, and the app is performing fine in the background. Make sense? – TomBomb Feb 11 '12 at 13:20
2

I finally found the answer, it's in the first response to this question:

How to prevent multiple instances of an activity when it is launched with different intents

Community
  • 1
  • 1
TomBomb
  • 3,236
  • 5
  • 31
  • 40
-1

This actually has nothing to do with the Market. If Android doesn't have enough resources to keep your app in memory, then it'll be removed from memory and it's process will be killed and onCreate will be called again the next time your app is started. What's probably happening is that Market is eating up all your device's memory when you install that way and causing the described behaviour.

aviraldg
  • 9,531
  • 6
  • 41
  • 56
  • This is what I thought initially, but watching the logs, the app continues in the background just fine. There is no crash or onDestroy or anything strange until I click the icon again and onCreate is called. – TomBomb Feb 11 '12 at 06:45
  • Hmm... that's strange. Does your app launch and work properly as expected? A logcat might shine some more light on the issue (because what you're describing clearly goes against the usual app lifecycle) – aviraldg Feb 11 '12 at 06:54
  • Yes, it launches and works just fine. The only issue seems to be this re-creating of the main activity when the user returns to the app. – TomBomb Feb 11 '12 at 20:26