安卓:当恢复操作后,pressing家庭的应用程序,应用程序总是开始于根系活力 [英] Android: When resuming app after pressing home, app always starts at root Activity

查看:175
本文介绍了安卓:当恢复操作后,pressing家庭的应用程序,应用程序总是开始于根系活力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用例的游戏看起来这样:我有一个LoadingActivity,它加载(通过AsyncTask的,但是这并不重要),并存储所有的静态类需要游戏中的图形。装载完毕后,MenuActivity出现。通过这次活动,我可以启动其他活动,例如LikeBeginActivity。

My use case for a game looks so: I have a LoadingActivity, which loads (by AsyncTask, but this doesn't matter) and stores all the graphics needed for the game in a static class. After the loading finished, the MenuActivity appears. From this Activity I can launch other Activities like LikeBeginActivity.

这是清单的片段:

<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 invocations look like this:

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);
    }
});

恼人的问题是,当我在LevelbeginActivity和preSS HOME,并启动恢复比赛,它总是起始于LoadingActivity,但为什么是整个任务清除?这是没有道理给我。于是我想到了加入

The annoying problem is that when I'm in the LevelbeginActivity and press HOME, and resume the game by launcher, it always starts at LoadingActivity, but why is the whole task cleared? That doesn't make sense to me. Then I thought about adding

android:alwaysRetainTaskState="true"

在清单中的LoadingActivity,但是这并没有帮助的。为什么会再次启动整个任务?这是很成问题,因为我耗尽内存,如果LoadingActivity开始一遍又一遍。 (下一个问题将是后退按钮行为,但那是另一个问题)。我可以鼓捣一些丑陋的装载行为通过保存最后一个活动的名称作为共享preferences什么的,但我宁愿preFER干净地解决了这个。

to the LoadingActivity in the manifest, but this doesn't help either. Why does it start the whole task again? This is very problematic because I run out of memory if the LoadingActivity is started over and over again. (The next issue will be the back button behaviour, but that's another problem). I could tinker some ugly loading behaviour by saving the last Activity name as SharedPreferences or something, but I'd rather prefer a clean solution to this.

推荐答案

Android将破坏活动如果系统需要的内存。你必须确保你保存的onSaveInstanceState()的活动的状态,使用户可以手动恢复它之后。您可以保存所需的值共享preferences 或一个 SQLiteDatabase

Android will destroy Activities if the system needs the memory. You have to make sure that you save the state of your Activity in onSaveInstanceState() so that you can manually resume it afterwards. You can save the needed values in SharedPreferences or in an SQLiteDatabase

这篇关于安卓:当恢复操作后,pressing家庭的应用程序,应用程序总是开始于根系活力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆