简体   繁体   中英

Titanium Android activity not maintaining state

I am trying to set up a mobile website that opens my mobile app when a link is clicked in the Android browser. To accomplish this task, I added an intent filter to AndroidManifest.xml, as seen in the code below:

<activity android:name=".MyAppActivity" android:label="@string/app_name" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden|orientation" android:alwaysRetainTaskState="true" android:launchMode="singleInstance">
<intent-filter>
<data android:scheme="myapp" android:host="app"/>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>

The link itself in the browser works great, and I'm easily able to gather parameters when the app is first opened using Ti.Android.currentActivity. The problem comes when the app is already open, but a user clicks the link to open it from within the mobile browser. When my app opens, instead of resuming where I left off before, I simply see the splashscreen. This goes both ways: If I opened the app first from the mobile browser, then tried to resume it later from the Android homescreen or app drawer, I only see the splash screen. Per tips I saw on other places of the internet, I tried adding the code below to AndroidManifest.xml (as seen above):

android:alwaysRetainTaskState="true" android:launchMode="singleInstance"

This however, appears to have no effect on anything, and the same problem persists. What am I missing here? Any help would be greatly appreciated.

The way i have done was like this

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="18"/>
    <manifest android:installLocation="preferExternal"
        android:versionCode="1" android:versionName="1.0">
        <uses-permission android:name="android.permission.CALL_PHONE"/>
        <application android:label="App Name" android:largeHeap="true">
            <activity
                android:configChanges="keyboardHidden|orientation|screenSize"
                android:label="@string/app_name"
                android:launchMode="singleTop"
                android:name=".mainActivity" android:theme="@style/Theme.Titanium">
                <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.VIEW"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                    <category android:name="android.intent.category.BROWSABLE"/>
                    <data android:scheme="schemaname"/>
                </intent-filter>
            </activity>
        </application>
    </manifest>
</android>

and its working fine for me . for Android 4.XX

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM