我正在为 android 设计一款游戏,我只想拥有它的一个实例。
游戏有一个我称之为 GameActivity 的主要活动和另一个我称之为 CreateAccountActivity 的活动。
我在清单中将 GameActivity 定义为android:launchMode="singleTask"
.
当应用程序第一次启动时,我使用startActivityForResult
方法启动 CreateAccoutActivity。
问题是,当我点击主页按钮然后启动我的应用程序时,什么也没有发生(从用户的角度来看,但我从日志中看到 CreateAccountActivity 被销毁,GameActivityonActivityResult
被调用然后它也被销毁(它RESULT_CANCEL
偏离了方向。
这是日志:
12-28 14:30:11.910: V/WindowManager(24745): Dsptch > Window{47ce9868 com.sec.android.app.twlauncher/com.sec.android.app.twlauncher.Launcher paused=false}
12-28 14:30:11.910: V/InputDevice(24745): ID[0]=0(0) Dn(0=>1)
12-28 14:30:11.973: D/dalvikvm(7770): GC_EXTERNAL_ALLOC freed 313 objects / 12648 bytes in 25ms
12-28 14:30:12.004: V/InputDevice(24745): ID[0]=0(0) Up(1=>0)
12-28 14:30:12.039: D/dalvikvm(7770): GC_EXTERNAL_ALLOC freed 88 objects / 2680 bytes in 25ms
12-28 14:30:12.110: D/dalvikvm(7770): GC_EXTERNAL_ALLOC freed 24 objects / 864 bytes in 25ms
12-28 14:30:12.157: V/WindowManager(24745): Dsptch > Window{47ce9868 com.sec.android.app.twlauncher/com.sec.android.app.twlauncher.Launcher paused=false}
12-28 14:30:12.157: I/ActivityManager(24745): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.*****.tq/.GameActivity }
12-28 14:30:12.161: D/Launcher.Workspace(7770): WorkspaceDraw: Workspace drawWallpaperImage()
12-28 14:30:12.168: I/CreateAccountActivity(9369): onDestroy
12-28 14:30:12.172: I/Launcher(7770): onPause()
12-28 14:30:12.184: W/Launcher(7770): WallpaperManager setVisibility visible true
12-28 14:30:12.203: I/GameActivity(9369): Game activity onActivityResult
12-28 14:30:12.203: I/GameActivity(9369): disconnecting from main server
12-28 14:30:12.203: I/ConnectionManager(9369): Disconnecting...
12-28 14:30:12.207: I/GameActivity(9369): Game activity onNewIntent is called
12-28 14:30:12.215: I/Launcher(7770): onWindowFocusChanged(false)
12-28 14:30:12.219: I/Launcher(7770): onResume(). mIsNewIntent : false
12-28 14:30:12.219: E/Launcher(7770): MTP-LAUNCHER: media scanning not yet finished .
12-28 14:30:12.219: I/Launcher(7770): onResume() ended
12-28 14:30:12.219: I/Launcher(7770): onWindowFocusChanged(true)
12-28 14:30:12.223: W/InputManagerService(24745): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@47d9fa18
12-28 14:30:12.227: D/Launcher.Workspace(7770): WorkspaceDraw: Workspace drawWallpaperImage()
12-28 14:30:12.235: I/GameActivity(9369): Game activity destroyed
12-28 14:30:12.762: D/BatteryService(24745): update start
12-28 14:30:12.770: D/BatteryService(24745): updateBattery level:100 scale:100 status:5 health:2 present:true voltage: 4240 temperature: 360 technology: Li-ion AC powered:false USB powered:true icon:17302163
12-28 14:30:12.801: I/StatusBarPolicy(24745): BAT. status:5 health:2
12-28 14:30:12.801: D/WifiService(24745): ACTION_BATTERY_CHANGED pluggedType: 2
12-28 14:30:13.231: W/Launcher(7770): WallpaperManager setVisibility visible false
12-28 14:30:13.375: D/Launcher.Workspace(7770): WorkspaceDraw: Workspace drawWallpaperImage()
为简单起见,我这样描述:Activity A = MAIN - singleTask Activity B = (undefined - standard)
A startsForResult B -> 主页按钮 -> 游戏启动按钮 -> B 已销毁 -> A onActivityResult 被调用 -> A 已销毁 -> 游戏启动按钮 -> A starttForResult B ...
编辑
我现在怀疑我是否需要使用 singleTask。
是真的吗,无论我从哪里开始我的活动由 android 而不是我编码的意图,android 总是会重新启动我的应用程序并且不会有我的活动的多个实例?
如果是这样的话,一切都很好-ood :)