重新推出的Home键的活动,但是...只在第一次 [英] Re-launch of Activity on Home button, but...only the first time

查看:145
本文介绍了重新推出的Home键的活动,但是...只在第一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我开发的应用程序有一个怪异的行为的第一次,它被安装。如果用户背上出应用程序通常在第一时间,它将永远表现为它应该。如果用户使用home键的首次安装应用程序后,它把应用程序,就像它应该再次重新启动主屏幕,并启动一个活动的新版本中的旧的前面。

The application that I am developing has a weird behavior the first time that it is installed. If the user backs out of the application normally the first time, it will forever behave as it should. If the user uses the home button the first time after installing the application, it treats the application as though it should re-launch the home screen again and launch a new version of an activity in front of the old one.

所以,真的有两个问题就在眼前。我似乎无法化解两者。

So there are really two issues at hand. I can't seem to resolve both of them.

  1. 在保持从当它第一次在打home键,用户安装关闭应用程序。
  2. 在保留多个版本的应用程序从启动时,它这个(launchMode帮助这里一点,但第一个组件仍然会触发)。

我没有将其定义为任何事情的清单文件中的 launchMode 属性。所以,不应该有任何奇怪的行为,因为这样的结果。现在我已经尝试了应用程序的 launchmode 属性,看看我是否能得到它的运行方式便意,但似乎比这里只是更给它正确开展活动。没有理由,一个应用程序应该关闭自己的第一次,据我看到的时候,家里按钮是pressed。

I don't have the launchMode attribute in the manifest file defined as anything. So there shouldn't be any odd behavior as the result of this. I have experimented now with the launchmode attribute of the application to see if I could get it to behave the way it is intended, but there seems to be more to it here than just launching the activities properly. There is no reason that an application should close itself the first time as far as I can see when the home button is pressed.

我不使用 onUserLeaveHint 应用程序中的任一。我可以肯定,再次做搜索过的项目。所以,似乎没有成为home键试图在所有的任何压倒一切的。

I don't use the onUserLeaveHint within the application either. I had to be sure once again by doing a search over the project. So there doesn't seem to be any overriding of the home button attempted at all.

即使重新启动手机,home键恢复正常的行为。不知道是什么原因导致的初始安装对待home键作为标志从头开始的应用程序。

Even after re-starting the phone, the home button behaves normally again. Not sure what causes the initial installation to treat the home button as a flag to start the application from scratch.

在用户背上出应用程序的第一时间,该问题将被永久解决。在哪里我应该看看有什么想法?

Once the user backs out of the application the first time, the issue is permanently resolved. Any thoughts on where I should look?

最近有应用程序中进行搜索,看是否可能会触发因为SQLite数据库的方法导致一些奇怪的行为的 onUpgrade()分量才。

Recently there has been a search within the application to see if perhaps it triggers only then because of an onUpgrade() component of the SQLite database method causing some odd behavior.

@Override
public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion) {
                if (newVersion > oldVersion) {

           }
       }

或在可能与更新的清单文件触发,如果我是路过沿APK的更新版本以及一个设备有一个版本,它已经是比当前较低的另一个位置。然而,没有在这部分的code使我相信,这应该不会影响任何有关的启动顺序。

Or in another location that might trigger with an update from the manifest file if I was passing along a newer version of the APK along to a device that had a version on it already that was one lower than the current one. However, nothing in this part of the code leads me to believe that it should affect anything related to the launch sequence.

清单文件(具有名称改变)下面被提供的东西,目前正在应用程序中使用。

The manifest file (with names changed) is supplied below for what is currently being used in the application.

<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10"/>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="com.android.vending.CHECK_LICENSE"></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>

<uses-permission android:name="android.permission.VIBRATE" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA" android:required="false"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>

<application android:icon="@drawable/icon"
             android:label="@string/app_name"
             android:allowBackup="false"
             android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
             >
    <activity android:name=".MyMain"
              android:label="@string/app_name_with_version"
              android:screenOrientation="portrait"
              android:windowSoftInputMode="adjustPan"   />
    <activity android:name=".StartupActivity"
              android:label="@string/app_name"
              android:screenOrientation="portrait"
              >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity   android:name=".SelectActivity"  
                android:label="@string/app_name_with_version"
                android:screenOrientation="portrait"/>
    <activity   android:name=".ImageSelectionActivity"
                android:theme="@android:style/Theme.Dialog"
                android:label="@string/app_name_with_version"
                android:screenOrientation="portrait"
                android:configChanges="orientation|keyboardHidden"/>            
    <activity   android:name=".DetailsActivity"
                android:label="@string/app_name_with_version"
                android:screenOrientation="portrait"/>
    <activity   android:name=".EMailActivity"   
                android:label="@string/app_name_with_version"       
                android:screenOrientation="portrait"/>
    <activity   android:name=".SendTo" 
                android:label="@string/share_label" 
                android:theme="@android:style/Theme.Dialog" >
        <INTENT-FILTER>  
            <ACTION android:name="android.intent.action.MAIN">  
            <CATEGORY android:name="android.intent.category.LAUNCHER"/>  
            <INTENT-FILTER>  
                <ACTION android:name="android.intent.action.VIEW">  
                <CATEGORY android:name="android.intent.category.DEFAULT">  
                    <CATEGORY android:name="android.intent.category.BROWSABLE">  
                    <DATA android:scheme="callback" android:host="twitter"/>  
                    </CATEGORY>  
                </CATEGORY>
                </ACTION>
            </INTENT-FILTER>
            </ACTION>
        </INTENT-FILTER>
    </activity>
    <activity   android:name=".CreateMyActivity"
                android:label="@string/create_account_label"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Dialog"/>
    <activity   android:name=".ViewInLayoutActivity"
                android:label="@string/app_name_with_version"   
                android:screenOrientation="portrait"/>
    <activity   android:name=".Preferences"
                android:label="@string/set_preferences" 
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Dialog"/>
    <activity   android:name=".AboutActivity"   
                android:label="@string/app_name_with_version"       
                android:screenOrientation="portrait"/>
    <activity   android:name=".InteractiveActivity" 
                android:label="@string/app_name_with_version"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Dialog"/>   
    <activity   android:name=".AlertFailedCommunications"
                android:screenOrientation="portrait"
                android:label="@string/alert_account_label"
                android:theme="@android:style/Theme.Dialog"/>
</application>    

推荐答案

欢迎到用户谁也咬了这一个不断成长的名单。

Welcome to the ever-growing list of users who have been bitten by this one.

这是一个众所周知的,长期的Andr​​oid漏洞。在这样的应用得到在第一时间推出从安装程序,网页浏览器,并通过IDE(的IntelliJ,Eclipse的,等)。见提起不久前与问题有关的这些问题:

This is a well-known and long-standing Android bug. in the way applications get launched the first time from the installer, web-browser and via IDE (IntelliJ, Eclipse, etc.). See these issues filed long ago related to the problem:

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

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

这仍然是断开的,你不能prevent这种情况的发生。你能做的唯一一件事就是为检测时,Android已经推出了根活动的第二个实例到现有的任务

It is still broken and you cannot prevent this from happening. The only thing you can do is to detect when Android has launched a second instance of your root activity into an existing task. You can do this by putting this code in onCreate() of your root activity:

if (!isTaskRoot()) {
    // Android launched another instance of the root activity into an existing task
    //  so just quietly finish and go away, dropping the user back into the activity
    //  at the top of the stack (ie: the last state of this task)
    finish();
    return;
}

这篇关于重新推出的Home键的活动,但是...只在第一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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