恢复后如何运行上次查看的活动?

时间:2015-04-13 07:47:50

标签: java android

我有一个Android应用程序。如果我通过活动(例如MainTabActivity-> SearchMapActivity-> ListBranchesActivity)然后隐藏(不关闭)我的应用程序,android将在重新打开后运行main(MainTabActivity)活动。如果我按"返回"按钮,android会显示最后一个活动(ListBranchesActivity)。如何让我的应用程序在恢复后显示最后一个活动?我真的不知道如何实现这一目标。有人说要向清单添加singleTask语句。 我的清单:

 <application
       android:allowBackup="true"
       android:icon="@drawable/ic_launcher"
       android:label="@string/app_name"
       android:theme="@android:style/Theme.Holo" 
       android:largeHeap="true"  >  


        <activity
            android:name=".SearchMapActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize"> 

            <intent-filter>             
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            </activity>         

            <activity
            android:name=".UpdateActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize"> 
                    <intent-filter>             
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            </activity> 

            <activity
            android:name=".CompanyInfoActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize"> 
                    <intent-filter>             
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            </activity> 

            <activity
            android:name=".FullMapActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize"> 
                <intent-filter>             
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.BROWSABLE"/>
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>        
            </activity> 

            <activity
            android:name=".ListBranchesActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize"> 
                <intent-filter>             
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.BROWSABLE"/>
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>        
            </activity> 

            <activity
            android:name=".ListCompaniesByBranchActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize"> 
                <intent-filter>             
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.BROWSABLE"/>
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>        
            </activity> 

            <activity
            android:name=".SearchResultActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">  


                <intent-filter>             
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.BROWSABLE"/>
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>        
            </activity> 



        <activity
            android:name=".MainTabActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboardHidden|orientation|screenSize">
            <intent-filter>

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

此外,事情并非每次都发生。有时它显示最后的活动,有时 - 主要活动。

1 个答案:

答案 0 :(得分:0)

 > Also that thing doesn't happen everytime. Sometimes 
 > it shows last activity, sometimes - main activity. 

如果需要内存,有时android会关闭你的应用程序。所以,即使你hide(not close) ...[the] application,它可能已被关闭