简体   繁体   English

Titanium Android活动无法保持状态

[英]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. 我试图建立一个移动网站,当在Android浏览器中单击链接时打开我的移动应用程序。 To accomplish this task, I added an intent filter to AndroidManifest.xml, as seen in the code below: 为了完成此任务,我向AndroidManifest.xml添加了一个意图过滤器,如以下代码所示:

<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. 浏览器中的链接本身很好用,当我第一次使用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. 这是双向的:如果我先从移动浏览器中打开了该应用程序,然后又试图从Android主屏幕或应用程序抽屉中恢复它,那么我只会看到启动屏幕。 Per tips I saw on other places of the internet, I tried adding the code below to AndroidManifest.xml (as seen above): 根据我在互联网上其他地方看到的提示,我尝试将以下代码添加到AndroidManifest.xml中(如上所示):

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 适用于Android 4.XX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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