简历,而不是开始启动活动在顶 [英] Resume the Top Activity instead of starting the Launcher Activity

查看:246
本文介绍了简历,而不是开始启动活动在顶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序的两项活动,一个是发射器和其他启动从第一一个显式调用。

下面我的问题是,当我回到主屏幕由次活动pressing主页键和启动应用程序,又是第一个活动被启动,即使第二个活动是已经在后台运行。

第一个活动是写下载所需的资产应用程序的工作,一旦资产被下载它触发第二个活动,并呼吁完成自我。

下面是我的应用程序的清单。


 <采用-SDK安卓的minSdkVersion =7机器人:targetSdkVersion =14/><应用机器人:图标=@绘制/图标机器人:标签=@字符串/ APP_NAME机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen>    &LT ;!下载所需的资产,如果不是在SD卡中 - >
    <活动机器人:名字=。ContentDownload
        机器人:screenOrientation =风景
        android:configChanges=\"keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|locale\"
        机器人:launchMode =singleTask
        机器人:alwaysRetainTaskState =真正的>        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>
            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.SEARCH/>
            <类机器人:名字=android.intent.category.DEFAULT/>
        &所述; /意图滤光器>    < /活性GT;    <活动机器人:名字=。ActualAppActivity
        机器人:screenOrientation =风景
        android:configChanges=\"keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|locale\"
        机器人:launchMode =singleTask
        机器人:alwaysRetainTaskState =真
        /><使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.MODIFY_AUDIO_SETTINGS/>
<使用许可权的android:NAME =android.permission.READ_PHONE_STATE/>
<使用许可权的android:NAME =android.permission.VIBRATE/>
<使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
<使用许可权的android:NAME =android.permission.CHANGE_NETWORK_STATE/>
<使用许可权的android:NAME =android.permission.ACCESS_WIFI_STATE/><支持屏安卓smallScreens =false的机器人:normalScreens =真正的机器人:largeScreens =真正的机器人:anyDensity =真/>

有人可以请指导我如何使次活动获得直接的控制,而不是通过再次率先将发射器是否被调用,它是在后台。

下面是我的onResult回拨方法。

 公共无效onResult(字符串assetPath,INT结果)
{
    如果(结果== RESULT_OK)
    {
        startActivity(新意图(这一点,ActualAppActivity.class));
        activity.destroyDownloadActvity();
        完();
    }
    其他
    {
        完();
        java.lang.System.exit(0);
    }
    activity.destroyDownloadActvity();
    活性=无效;
}


解决方案

请尝试使用在指定为启动活动清单中的活动的onCreate方法如下code,即从原来的ContentDownload活动code张贴在这个问题:

 如果((getIntent()getFlags()及!Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)= 0){
  完();
  返回;
}

之前,通过检测,已经有正在运行的任务,并且您的应用程序而应该恢复到最后一个可见的活动,显示此将完成您的发射活动。

对于Android清单launchModes Android的文档中看到这个页面:<一href=\"http://developer.android.com/reference/android/R.styleable.html#AndroidManifestActivity_launchMode\">http://developer.android.com/reference/android/R.styleable.html#AndroidManifestActivity_launchMode

I have two activities in My application, one being launcher and the other is launched as a explicit call from the first.

Here My problem is when i go back to home screen by pressing home key from second activity and launch the application, again the first activity gets initiated even though the second activity is already in the background.

The first Activity is written to download the required assets for the application to work, once the assets are downloaded it triggers the second activity and calls finish for self.

Below is my manifest of the application.

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

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">

    <! Download the Required Assets if not found on SD Card -->
    <activity android:name=".ContentDownload"
        android:screenOrientation="landscape"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|locale" 
        android:launchMode="singleTask"
        android:alwaysRetainTaskState="true">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

    </activity>

    <activity android:name=".ActualAppActivity" 
        android:screenOrientation="landscape" 
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|locale" 
        android:launchMode="singleTask"
        android:alwaysRetainTaskState="true"
        />

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>  

<supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/>

Can Somebody please guide me on how to make the second activity gain the control directly instead of going through the first again if launcher is called and it is in the background.

Below is my onResult Call back method.

public void onResult(String assetPath, int result)
{
    if(result == RESULT_OK)
    {
        startActivity(new Intent(this, ActualAppActivity.class));
        activity.destroyDownloadActvity();
        finish();
    }
    else
    {
        finish();
        java.lang.System.exit(0);
    }
    activity.destroyDownloadActvity();
    activity = null;
}

解决方案

Try using the following code in the onCreate method of the activity that is specified as the Launcher Activity in the Manifest, i.e. the ContentDownload activity from the original code posted in the question:

if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
  finish();
  return;
}

This will finish your Launcher Activity before it is displayed by detecting that there is already a task running, and your app should instead resume to the last visible Activity.

See this page in the Android documentation regarding Android Manifest launchModes: http://developer.android.com/reference/android/R.styleable.html#AndroidManifestActivity_launchMode

这篇关于简历,而不是开始启动活动在顶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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