How to deal with android multiple instances? -
the launchmode "singletop":
<activity android:name=".mainactivity" android:label="@string/app_name" android:launchmode="singletop"> <intent-filter> <action android:name="android.intent.action.main"/> <category android:name="android.intent.category.launcher"/> </intent-filter> </activity> <activity android:name=".gridactivity"></activity>
the mainactivity splash screen, when finish (authenticate server) it'll call gridactivity.
the problem specific:
when install app google play icon appear in 2 places: application drawer & "desktop" (launcher screen - default launcher).
steps reproduce problem:
- open app application drawer , wait gridactivity displayed
- press "home" button send application background
- open app "desktop" (device's default launcher)
- the application start in new instance
i expect application go directly gridactivity because of "singletop" launchmethod.
btw, if on step 3 open application again application drawer works fine, goes directly gridactivity.
what missing?
because you;re using launch activity "splash screen" getting destroyed, leads behavior. once destroyed, process calling launch in new process. read more:
android "single top" launch mode , onnewintent method
the "singletop" launch mode not necessary. although around this, use "first time through" flag launches splash screen main activity. seems work pretty well.
edit:
you should careful read on "launchmode" - singletop , "standard" modes have behavior, docs:
an activity "standard" or "singletop" launch mode can instantiated multiple times.
http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
you experiencing aspect of singletop
:
for example, if existing instance of "singletop" activity in target task, not @ top of stack, or if it's @ top of stack, not in target task — new instance created , pushed on stack.
the 2 launch locations resulting in 2 different target tasks. because of how 2 screens create intents or because "splashscreen" destroyed , therefore not present (it not "only" destroyed hitting - android has several algorithms destroying activities conserve processing , memory. should assume if activity not visible, can destroyed , re-created @ time).
Comments
Post a Comment