I encountered this strange problem with my activity. I am sure the reason for this is documented somewhere but my search efforts have been in vain so-far.
To summarise the problem - my onCreate()
is being called while the activity is in a paused state. According to all the life-cycle flow diagrams I have seen - this should never happen.
Here is (I think) the relevant info from my manifest:
<activity
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/xml" />
<data android:mimeType="application/xml" />
<data android:pathPattern=".*\\.xml" />
</intent-filter>
</activity>
Let's say I start my application in the usual way by clicking on the icon. I then hit the home button. I can see that the OS calls onPause()
- but not onDestroy()
- which is what I expect.
If at this point I find an xml file and use my application to open it I see onCreate()
being called - why does this happen?
I probably wouldn't even have noticed if it wasn't for the fact that my onCreate()
initialises a rather large memory cache as a fragment and for this subsequent startup the findFragmentByTag returns null, even though the application that exists in the resumed state has already created this and I end up with an OutOfMemory
exception.
Hopefully someone can shed a light on this.
Thanks,
Lew