重新启动Home on Home按钮,但是......仅在第一次

Jay*_*der 43 android

我正在开发的应用程序在第一次安装时有一种奇怪的行为.如果用户第一次正常退出应用程序,它将永远按预期运行.如果用户在安装应用程序后第一次使用主页按钮,它会将应用程序视为应该再次重新启动主屏幕并在旧版本之前启动新版本的活动.

所以手头有两个问题.我似乎无法解决这两个问题.

  1. 在用户点击主页按钮时首次安装应用程序时,请保持应用程序关闭.
  2. 保持应用程序的多个版本在执行此操作时启动(launchMode有点帮助,但第一个组件仍然触发).

我没有launchMode将清单文件中的属性定义为任何内容.因此,不应该有任何奇怪的行为.我现在已经尝试launchmode了应用程序的属性,看看我是否能够按照预期的方式运行它,但是这里似乎还有更多的东西,而不仅仅是正确地启动活动.当我按下主页按钮时,应用程序应该第一次关闭自己是没有理由的.

我也没有onUserLeaveHint 在应用程序中使用.通过对项目进行搜索,我必须再次确定.所以似乎根本没有尝试覆盖主页按钮.

即使重新启动手机,主页按钮也会再次正常运行.不确定是什么原因导致初始安装将主页按钮视为从头开始启动应用程序的标志.

一旦用户第一次退出应用程序,问题就会永久解决.关于我应该在哪里看的任何想法?

最近在应用程序中进行了一次搜索,以查看是否它只是因为onUpgrade()SQLite数据库方法的一个组件导致一些奇怪的行为而触发.

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

           }
       }
Run Code Online (Sandbox Code Playgroud)

或者在另一个可能触发清单文件更新的位置,如果我将新版本的APK传递给其上有版本的设备已经低于当前版本.但是,在这部分代码中没有任何内容让我相信它应该影响与启动序列相关的任何事情.

清单文件(名称已更改)在下面提供,用于应用程序当前使用的内容.

<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>    
Run Code Online (Sandbox Code Playgroud)

Dav*_*ser 68

欢迎来到不断增长的用户名单.

这是一个众所周知且长期存在的Android漏洞.第一次从安装程序,Web浏览器和IDE(IntelliJ,Eclipse等)启动应用程序的方式.请参阅很久以前提出的与此问题相关的问题:

http://code.google.com/p/android/issues/detail?id=2373

http://code.google.com/p/android/issues/detail?id=26658

它仍然破碎,你无法防止这种情况发生.您唯一能做的就是检测Android何时将根活动的第二个实例启动到现有任务中.您可以通过将此代码放入onCreate()根活动中来执行此操作:

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;
}
Run Code Online (Sandbox Code Playgroud)

  • 我的荣幸.如果您要查看Google代码中引用的问题并对其进行加注/评论,我将不胜感激.我们对此产生的噪音越多,在未来版本中修复的可能性就越大.作为临时修复,您可以告诉用户在安装应用程序后不要单击"打开"按钮.另请注意,通过安装程序升级应用程序后也会发生这种情况. (3认同)

Rvd*_*vdK 5

为什么这是表现,没有线索.但我知道自定义Launcher有特定的launchModes设置.

例如ADW.Launcher:

android:clearTaskOnLaunch="true"
android:launchMode="singleTask" 
Run Code Online (Sandbox Code Playgroud)

Android SDK示例中的主页应用程序: android-sdk\samples\android-16\Home\AndroidManifest.xml

android:launchMode="singleInstance"
Run Code Online (Sandbox Code Playgroud)

引用CommonsWare:如何阻止自定义家庭启动器应用重启活动?

我将使用SDK中的Home示例应用程序,它使用singleInstance.奇怪的是,AOSP发射器使用singleTask