How should I define launchMode in AndroidManifest.xml - Using PhoneGap & JQM

前端 未结 4 1480
予麋鹿
予麋鹿 2020-12-29 08:18

I am struggling to restrict my application to a single instance. Currently if the user presses home screen to quit the application, then does something outside and clicks on

相关标签:
4条回答
  • 2020-12-29 08:47

    Try with

    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTop" android:name="HomePage" android:theme="@android:style/Theme.DeviceDefault">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    it's what's generated by phonegap CLI and launchmode set to singleTop to have single instance.

    android:name must match the name of the main java class of the activity, not the full package name. By default phonegap sets it as the app name.

    0 讨论(0)
  • 2020-12-29 08:48

    This is what ultimately worked for me:

    However the trick is that you need to change in two locations:

    A) MyAppFolder\platforms\android\AndroidManifest.xml

    <activity android:alwaysRetainTaskState="true" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:launchMode="singleTask" android:name="AppName" android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    

    B) MyAppFolder\www\AndroidManifest.xml

    <activity
                android:name="AppName"
                android:launchMode=["singleTask"]
                android:alwaysRetainTaskState="true"
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
    </activity>
    

    Hope that helps someone.

    0 讨论(0)
  • 2020-12-29 08:56

    I struggled with this problem for 2 days. The fix for adding this attribute was only recently added to Cordova as of 3.5, issue CB-6048

    add:

    <preference name="AndroidLaunchMode" value="singleTask" />
    

    to config.xml

    Other available values:

    • "standard"
    • "singleTop"
    • "singleTask"
    • "singleInstance"
    0 讨论(0)
  • 2020-12-29 08:59

    try this:

    <gap:config-file platform="android" parent="/manifest/application">
        <activity android:launchMode="singleInstance" />
    </gap:config-file>
    

    but in your config's widget setting, it should be like this (add the android namespace definition):

    <widget xmlns     = "http://www.w3.org/ns/widgets"
            xmlns:gap = "http://phonegap.com/ns/1.0"
            xmlns:android = "http://schemas.android.com/apk/res/android"
            id        = "com.wildabeast.app"
            version   = "1.0.0">
    ....
    </widget>
    
    0 讨论(0)
提交回复
热议问题