My use case for the game looks like this: I have a LoadActivity that loads (according to AsyncTask, but that doesn't matter) and saves all the graphics needed to play in a static class. When the download is complete, MenuActivity appears. From this action, I can run other actions, such as LikeBeginActivity.
This is a snippet of the manifest:
<activity android:name="my.domain.mygame.LoadingActivity" android:alwaysRetainTaskState="true" android:screenOrientation="landscape"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="my.domain.mygame.MenuActivity" android:theme="@android:style/Theme.NoTitleBar" > </activity> <activity android:name="my.domain.mygame.LevelBeginActivity" android:theme="@android:style/Theme.NoTitleBar" > </activity>
The calls are as follows:
LoadingActivity
public void startMenu() { final Intent gameIntent = new Intent(this, MenuActivity.class); startActivity(gameIntent); }
MenuActivity
buttonStartNewGame.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent levelIntent = new Intent(MenuActivity.this, LevelBeginActivity.class); levelIntent.putExtra(IntentConstants.STARTLEVELINDEX, 0); startActivity(levelIntent); } });
The annoying problem is that when I am in LevelbeginActivity and I press HOME and resume the game with the launcher, it always starts with LoadActivity, but why is this whole task cleared? That doesn't make sense to me. Then I thought about adding
android:alwaysRetainTaskState="true"
for LoadingActivity in the manifest, but that doesn't help either. Why does he run the whole task again? This is very problematic because I am running out of memory if LoadingActivity starts up again and again. (The next question will be the behavior of the back button, but this is another problem). I could spoil some ugly loading behavior by storing the last Activity name as SharedPreferences or something like that, but I would prefer a clean solution for this.
Bevor source share