我怎样才能让一个Android应用程序停止重启每次打开它时? [英] How can I make an android app stop restarting every time it is opened?

查看:129
本文介绍了我怎样才能让一个Android应用程序停止重启每次打开它时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个小的Andr​​oid应用程序,最近发现了一个奇怪的现象。

I developed a small android application and recently discovered a strange behavior.

当我使用USB和eclipse我可以离开应用程序,进入到Android主屏幕或其他应用程序,然后返回到直接提到的任意活动以启动的应用程序再次安装该应用程序后,浏览到一个任意活动。

When I navigate to an arbitrary Activity after installing this app using usb and eclipse I can leave the app, go to the android home screen or another application and then return to the mentioned arbitrary Activity directly by "starting" the application again.

但是,当我直接下载APK文件安装在手机上的应用程序,我会一直返回到应用程序的根目录下活动,当我回到这个程序后,我切换到另一个应用程序或Android主屏幕。

But when I install the application on the phone directly by downloading the apk-file, I will always return to the root Activity of the application when I return to this app, after I switched to another application or the android home screen.

有谁知道这种行为是来自或如何,我可以解决这个问题?

Does anybody know where this behavior comes from or how I can fix this issue?

更新:的我运行在这两种情况在实际硬件上的应用程序

UPDATE: I run the application on real hardware in both cases.

推荐答案

将以下code到根活动终于修复了这个问题。

putting the following code to the root Activity fixed this issue finally.

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
        // Activity was brought to front and not created, 
        // Thus finishing this will get us to the last viewed activity 
        finish(); 
        return; 
    } 

}

来源:的<一个href="http://stackoverflow.com/questions/2280361/app-always-starts-fresh-from-root-activity-instead-of-resuming-background-state">App总是开始从新鲜根系活力,而不是恢复的背景状态(已知错误)

这篇关于我怎样才能让一个Android应用程序停止重启每次打开它时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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