TomBomb
TomBomb

Reputation: 3296

Android - onCreate being called on every launch

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?

Upvotes: 2

Views: 6633

Answers (3)

TomBomb
TomBomb

Reputation: 3296

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

Upvotes: 2

Bill Gary
Bill Gary

Reputation: 3005

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

Upvotes: 2

aviraldg
aviraldg

Reputation: 9154

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.

Upvotes: -1

Related Questions