Android的活动堆栈无法正常工作,在文档中阐明的 - 在任务堆栈最后一项活动未显示 [英] Android Activity Stack is not working as stated in the docs - last activity in task stack not shown

查看:98
本文介绍了Android的活动堆栈无法正常工作,在文档中阐明的 - 在任务堆栈最后一项活动未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据Android的文档:

According to Android docs:

http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html

当用户离开由pressing Home键任务,当前活动停止,它的任务进入后台,系统保留在任务的每一次活动的状态。如果用户以后重新开始通过选择开始该任务的启动器图标任务,任务涉及到前景和恢复在堆栈的顶部的活性。

"When the user leaves a task by pressing the Home button, the current activity is stopped and its task goes into the background. The system retains the state of every activity in the task. If the user later resumes the task by selecting the launcher icon that began the task, the task comes to the foreground and resumes the activity at the top of the stack."

如果我正确地理解这一点,这意味着:

If I understand this correctly, this means:

  1. 在活动A作为主要活动。
  2. 在得到启动的一个,通过startActivityb活动 - 普通,普通的意图例如
  3. 在我打开应用程序的第一次,一个被载入。
  4. 我在一个点击按钮和B的双头呆。
  5. 在我preSS HOME键。
  6. 在我再次打开的应用程序,为第二次,而B预计将显示

...对吧? 我想这是预期正确的行为...

...right? I suppose this is the correct behavior to expect...

不过,我没有看到这个在我的应用程序。

However, I am not seeing this in my app.

如果我点击Home键,然后恢复我的应用程序,以pressing发射器的图标,它就会开始与主要活动 - 而不是一个在顶部或最新一期

If I hit "Home button" and then resume my app, by pressing the launcher icon, it will start with the main activity - not the one at the top or latest one.

我编码在三星Galaxy Tab的Andr​​oid 2.2.1 - 我已经在Android清单中最常用的选项 - 事情是,我处理这样的不同意图额外10个不同的活动 - 和Dispatcher类的方法 - 或保存每个活动状态 - 听上去相当苛刻

I am coding on a Samsung Galaxy Tab Android 2.2.1 - I have the most common options in the Android manifest - thing is that I handle like 10 different activities with different intent extras - and a Dispatcher class approach - or save each activity state - sounds quite demanding.

我使用的Eclipse IDE与ADT 12版;我发现了一些很有趣的:

I am using Eclipse IDE with ADT version 12; and I found something very interesting:

当我运行Eclipse IDE中的应用程序,我的设备相连,我没有看到这种行为。该应用程序的行为与在文档中阐明。 事实上,我看到这个后,才部署了我的apk在谷歌Play应用资源库;并将其下载到测试。

When I run the app from the Eclipse IDE, with my device connected, I don't see this behavior. The app behaves as stated in the docs. In fact, I saw this only after I deployed my apk at the Google Play app repository; and downloaded it to test.

我的问题是,已经有人找到了真正的原因会出现这种情况? 是的文件错了吗?还是失去了一些东西? 这是在Android上一个错误?

My question is, has anybody found the real reason why is this happening? Is the documentation wrong? or missing something? Is this a bug on Android?

另外一个研究,我所做的是:

Another research I have done is:

当我尝试我的应用程序,从谷歌播放下载的,因为APK,如果我进入我的应用程序的第二次,我得到的最后一个双头呆的主的活动来代替。我preSS家。 经过pressing回家,我进入应用管理设置为Android,找到我的应用程序,然后单击强制停机。 这样做后,应用程序表现为在文档中阐明。

When I try my app, downloaded from the google play, as APK, if I enter my app for the 2nd time, I get the "main" activity instead of the last one openend. I press home. After pressing home, I enter application management settings for android, locate my app and click on "force stop". After doing this, the app behaves as stated in the docs.

有人帮! :)

推荐答案

这是在Android的平台中的错误:

This is a bug in android's platform:

<一个href="http://$c$c.google.com/p/android/issues/detail?id=2373">http://$c$c.google.com/p/android/issues/detail?id=2373

解决方法是,把这个在您的主要活动的onCreate方法:

The workaround is, to place this in the onCreate method of your main Activity:

if (!isTaskRoot())
{
    final Intent intent = getIntent();
    final String intentAction = intent.getAction(); 
    if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN))
    {
        Log.w(LOG_TAG, "Main Activity is not the root.  Finishing Main Activity instead of launching.");
        finish();
        return;       
    }
}

摘自:

<一个href="http://stackoverflow.com/questions/4341600/how-to-$p$pvent-multiple-instances-of-an-activity-when-it-is-launched-with-differ">How到活动prevent多个实例,当它与不同的意图是推出

...了3天找了这一点。

...spent 3 days looking out for this.

这篇关于Android的活动堆栈无法正常工作,在文档中阐明的 - 在任务堆栈最后一项活动未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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